function BXDeleteFromSystem($absoluteFilePath, $path, $site)
{
    $io = CBXVirtualIo::GetInstance();
    $f = $io->GetFile($absoluteFilePath);
    $f->MarkWritable();
    if (COption::GetOptionInt("main", "disk_space") > 0) {
        $file_size = $f->GetFileSize();
        $quota = new CDiskQuota();
        $quota->UpdateDiskQuota("file", $file_size, "delete");
    }
    $sucess = $io->Delete($absoluteFilePath);
    if (!$sucess) {
        return false;
    }
    if (COption::GetOptionString($module_id, "log_page", "Y") == "Y") {
        $res_log['path'] = substr($path, 1);
        CEventLog::Log("content", "PAGE_DELETE", "main", "", serialize($res_log));
    }
    $GLOBALS["APPLICATION"]->RemoveFileAccessPermission(array($site, $path));
    if (CModule::IncludeModule("search")) {
        CSearch::DeleteIndex("main", $site . "|" . $path);
    }
    //Delete from rewrite rule
    CUrlRewriter::Delete(array("SITE_ID" => $site, "PATH" => $path));
    if (class_exists("\\Bitrix\\Main\\Application", false)) {
        \Bitrix\Main\Component\ParametersTable::deleteByFilter(array("SITE_ID" => $site, "REAL_PATH" => $path));
    }
    return true;
}
function BXCreateSection(&$fileContent, &$sectionFileContent, &$absoluteFilePath, &$sectionPath)
{
    //Check quota
    $quota = new CDiskQuota();
    if (!$quota->CheckDiskQuota(array("FILE_SIZE" => strlen($fileContent) + strlen($sectionFileContent)))) {
        $GLOBALS["APPLICATION"]->ThrowException($quota->LAST_ERROR, "BAD_QUOTA");
        return false;
    }
    $io = CBXVirtualIo::GetInstance();
    //Create dir
    if (!$io->CreateDirectory($absoluteFilePath)) {
        $GLOBALS["APPLICATION"]->ThrowException(GetMessage("PAGE_NEW_FOLDER_CREATE_ERROR") . "<br /> (" . htmlspecialcharsbx($absoluteFilePath) . ")", "DIR_NOT_CREATE");
        return false;
    }
    //Create .section.php
    $f = $io->GetFile($absoluteFilePath . "/.section.php");
    if (!$GLOBALS["APPLICATION"]->SaveFileContent($absoluteFilePath . "/.section.php", $sectionFileContent)) {
        return false;
    }
    //Create index.php
    if (!$GLOBALS["APPLICATION"]->SaveFileContent($absoluteFilePath . "/index.php", $fileContent)) {
        return false;
    } else {
        if (COption::GetOptionString($module_id, "log_page", "Y") == "Y") {
            $res_log['path'] = $sectionPath . "/index.php";
            CEventLog::Log("content", "PAGE_ADD", "main", "", serialize($res_log));
        }
    }
    return true;
}
Exemple #3
0
 /**
  * <p>Метод удаляет файл из таблицы зарегистрированных файлов (b_file) и с диска. Статичный метод.</p>
  *
  *
  * @param int $id  Цифровой идентификатор файла.
  *
  * @return mixed 
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?
  * // удаляем изображение формы
  * $arFilter = array("ID" =&gt; 1, "ID_EXACT_MATCH" =&gt; "Y");
  * $rsForm = CForm::GetList($by, $order, $arFilter, $is_filtered);
  * if ($arForm = $rsForm-&gt;Fetch())
  * {
  *     if (intval($arForm["IMAGE_ID"])&gt;0) <b>CFile::Delete</b>($arForm["IMAGE_ID"]);	
  * }
  * ?&gt;
  * </pre>
  *
  *
  * <h4>See Also</h4> 
  * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/main/functions/file/deletedirfiles.php">DeleteDirFiles</a> </li>
  * <li> <a href="http://dev.1c-bitrix.ru/api_help/main/functions/file/deletedirfilesex.php">DeleteDirFilesEx</a> </li>
  * </ul><a name="examples"></a>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/main/reference/cfile/delete.php
  * @author Bitrix
  */
 public static function Delete($ID)
 {
     global $DB;
     $io = CBXVirtualIo::GetInstance();
     $ID = intval($ID);
     if ($ID <= 0) {
         return;
     }
     $res = CFile::GetByID($ID);
     if ($res = $res->Fetch()) {
         $delete_size = 0;
         $upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
         $dname = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $res["SUBDIR"];
         $fname = $dname . "/" . $res["FILE_NAME"];
         $file = $io->GetFile($fname);
         if ($file->isExists() && $file->unlink()) {
             $delete_size += $res["FILE_SIZE"];
         }
         $delete_size += CFile::ResizeImageDelete($res);
         $DB->Query("DELETE FROM b_file WHERE ID = " . $ID);
         $directory = $io->GetDirectory($dname);
         if ($directory->isExists() && $directory->isEmpty()) {
             $directory->rmdir();
         }
         CFile::CleanCache($ID);
         foreach (GetModuleEvents("main", "OnFileDelete", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($res));
         }
         /****************************** QUOTA ******************************/
         if ($delete_size > 0 && COption::GetOptionInt("main", "disk_space") > 0) {
             CDiskQuota::updateDiskQuota("file", $delete_size, "delete");
         }
         /****************************** QUOTA ******************************/
     }
 }
Exemple #4
0
 protected function processActionDefault()
 {
     $pathToAjax = isset($this->arParams['AJAX_PATH']) ? $this->arParams['AJAX_PATH'] : '/bitrix/components/bitrix/disk.bitrix24disk/ajax.php';
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $quota = CDiskQuota::getDiskQuota();
     $this->arResult['showDiskQuota'] = false;
     //$quota !== true; //now without quota
     $this->arResult['diskSpace'] = (double) COption::getOptionInt('main', 'disk_space') * 1024 * 1024;
     $this->arResult['quota'] = $quota;
     $this->arResult['ajaxIndex'] = $pathToAjax;
     $this->arResult['ajaxStorageIndex'] = '/desktop_app/storage.php';
     $this->arResult['isInstalledDisk'] = \Bitrix\Disk\Desktop::isDesktopDiskInstall();
     $this->arResult['personalLibIndex'] = '/company/personal/user/' . $this->getUser()->getId() . '/disk/path/';
     $this->arResult['isInstalledPull'] = (bool) isModuleInstalled('pull');
     $this->arResult['currentUser'] = array('id' => $this->getUser()->getId(), 'formattedName' => $this->getUser()->getFormattedName());
     Asset::getInstance()->addJs('/bitrix/components/bitrix/disk.bitrix24disk/disk.js');
     $this->includeComponentTemplate();
 }
Exemple #5
0
 function DELETE($options)
 {
     $io = self::GetIo();
     if (isset($options['path'])) {
         $options['path'] = $this->_udecode($options['path']);
     }
     $this->IsDir($options);
     if ($this->arParams["not_found"]) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
         return "404 Not found";
     }
     if (!$this->CheckRights("DELETE", true, $options["path"])) {
         $this->ThrowAccessDenied();
         return "403 Forbidden";
     }
     $quota = false;
     if (COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
     }
     $trashPath = $this->GetMetaID("TRASH");
     $arPath = explode("/", $this->arParams["item_id"]);
     if (!$this->arParams["is_dir"]) {
         //$file = $io->CombinePath($this->real_path_full, $this->arParams["item_id"]);
         //$path = $io->CombinePath($this->real_path, $this->arParams["item_id"]);
         $file = CWebDavBase::CleanRelativePathString($this->arParams["item_id"], $this->real_path_full);
         $path = CWebDavBase::CleanRelativePathString($this->arParams["item_id"], $this->real_path);
         if ($file === false || $path === false) {
             return "404 Not found";
         }
         $arPath = explode("/", $this->arParams["item_id"]);
         if ($arPath[1] != $this->meta_names["TRASH"]["name"] && !isset($options['force'])) {
             return $this->_move_to_trash($options, $this->arParams);
         } else {
             // in trash or options[force]
             $oFile = $io->GetFile($file);
             $file_size = $oFile->GetFileSize();
             if ($io->Delete($file)) {
                 $this->_delete_props($this->arParams['item_id']);
                 $GLOBALS["APPLICATION"]->RemoveFileAccessPermission(array(SITE_ID, $path));
                 if (CModule::IncludeModule("search")) {
                     CSearch::DeleteIndex("main", SITE_ID . "|" . $path);
                 }
                 if ($quota) {
                     $quota->updateDiskQuota("file", $file_size, "delete");
                 }
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
                 return "404 Not found";
             }
         }
     } else {
         if ($arPath[1] != $this->meta_names["TRASH"]["name"] && !isset($options['force'])) {
             return $this->_move_to_trash($options, $this->arParams);
         } else {
             $params = $this->GetFilesAndFolders($this->arParams["item_id"]);
             if (empty($params)) {
                 return true;
             }
             rsort($params, SORT_STRING);
             foreach ($params as $file) {
                 $path = str_replace($this->real_path_full, "", $file);
                 $path = $io->CombinePath("/", $path);
                 $file = $io->CombinePath($this->real_path_full, $path);
                 if (!$io->ValidatePathString($file)) {
                     return "404 Not found";
                 }
                 if ($io->FileExists($file)) {
                     //$path = str_replace($_SERVER['DOCUMENT_ROOT'], "", $file);
                     $oFile = $io->GetFile($file);
                     $file_size = $oFile->GetFileSize();
                     if ($io->Delete($file)) {
                         $this->_delete_props(str_replace(array($this->real_path_full, "///", "//"), "/", $file));
                         $GLOBALS["APPLICATION"]->RemoveFileAccessPermission(array(SITE_ID, $path));
                         if (CModule::IncludeModule("search")) {
                             CSearch::DeleteIndex("main", SITE_ID . "|" . $path);
                         }
                         if ($quota) {
                             $quota->updateDiskQuota("file", $file_size, "delete");
                         }
                     } else {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
                         return "404 Not found";
                     }
                 } elseif ($io->DirectoryExists($file)) {
                     $path = str_replace($_SERVER['DOCUMENT_ROOT'], "", $file);
                     if ($io->Delete($file)) {
                         $this->_delete_props(str_replace(array($this->real_path_full, "///", "//"), "/", $file));
                         $GLOBALS["APPLICATION"]->RemoveFileAccessPermission(array(SITE_ID, $path));
                     } else {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
                         return "404 Not found";
                     }
                 }
             }
             if ($path == $trashPath) {
                 $trashID = $this->GetMetaID('TRASH');
             }
         }
     }
     clearstatcache();
     return "204 No Content";
 }
Exemple #6
0
 public function CheckFields(&$arFields, $ID = false)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     $this->LAST_ERROR = "";
     $NAME = isset($arFields["NAME"]) ? $arFields["NAME"] : "";
     if (($ID === false || array_key_exists("NAME", $arFields)) && strlen($NAME) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_NAME") . "<br>";
     }
     if ($ID === false && !is_set($arFields, "IBLOCK_TYPE_ID")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE") . "<br>";
     }
     if ($ID === false) {
         //For new record take default values
         $WORKFLOW = array_key_exists("WORKFLOW", $arFields) ? $arFields["WORKFLOW"] : "Y";
         $BIZPROC = array_key_exists("BIZPROC", $arFields) ? $arFields["BIZPROC"] : "N";
     } else {
         //For existing one read old values
         $arIBlock = CIBlock::GetArrayByID($ID);
         $WORKFLOW = array_key_exists("WORKFLOW", $arFields) ? $arFields["WORKFLOW"] : $arIBlock["WORKFLOW"];
         $BIZPROC = array_key_exists("BIZPROC", $arFields) ? $arFields["BIZPROC"] : $arIBlock["BIZPROC"];
         if ($BIZPROC != "Y") {
             $BIZPROC = "N";
         }
         //This is cache compatibility issue
     }
     if ($WORKFLOW == "Y" && $BIZPROC == "Y") {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_WORKFLOW_AND_BIZPROC") . "<br>";
     }
     if (is_set($arFields, "IBLOCK_TYPE_ID")) {
         $r = CIBlockType::GetByID($arFields["IBLOCK_TYPE_ID"]);
         if (!$r->Fetch()) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE_ID") . "<br>";
         }
     }
     if (is_array($arFields["PICTURE"]) && array_key_exists("bucket", $arFields["PICTURE"]) && is_object($arFields["PICTURE"]["bucket"])) {
         //This is trusted image from xml import
     } elseif (isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]) && isset($arFields["PICTURE"]["name"])) {
         $error = CFile::CheckImageFile($arFields["PICTURE"]);
         if (strlen($error) > 0) {
             $this->LAST_ERROR .= $error . "<br>";
         }
     }
     if ($ID === false && !is_set($arFields, "LID") || is_set($arFields, "LID") && (is_array($arFields["LID"]) && count($arFields["LID"]) <= 0 || !is_array($arFields["LID"]) && strlen($arFields["LID"]) <= 0)) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SITE_ID_NA") . "<br>";
     } elseif (is_set($arFields, "LID")) {
         if (!is_array($arFields["LID"])) {
             $arFields["LID"] = array($arFields["LID"]);
         }
         foreach ($arFields["LID"] as $v) {
             $r = CSite::GetByID($v);
             if (!$r->Fetch()) {
                 $this->LAST_ERROR .= "'" . $v . "' - " . GetMessage("IBLOCK_BAD_SITE_ID") . "<br>";
             }
         }
     }
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockAdd", true);
     } else {
         $arFields["ID"] = $ID;
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockUpdate", true);
     }
     foreach ($db_events as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $APPLICATION->ThrowException("Unknown error");
                 $this->LAST_ERROR .= "Unknown error.<br>";
             }
             break;
         }
     }
     /****************************** QUOTA ******************************/
     if (empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (!$quota->checkDiskQuota($arFields)) {
             $this->LAST_ERROR = $quota->LAST_ERROR;
         }
     }
     /****************************** QUOTA ******************************/
     if (strlen($this->LAST_ERROR) > 0) {
         return false;
     }
     return true;
 }
Exemple #7
0
 function UploadFile($Params)
 {
     $buffer = 'parent.oWaitWindow.Hide();';
     $F = $Params['file'];
     $io = CBXVirtualIo::GetInstance();
     if (isset($F["tmp_name"]) && strlen($F["tmp_name"]) > 0 && strlen($F["name"]) > 0 || is_uploaded_file($F["tmp_name"])) {
         global $APPLICATION, $USER;
         $strWarning = '';
         $filename = $Params['filename'];
         $path = $Params['path'];
         $site = $Params['site'];
         $upload_and_open = $Params['upload_and_open'];
         $rootPath = CSite::GetSiteDocRoot($site);
         if ($filename == '') {
             $filename = $F["name"];
         }
         $pathto = Rel2Abs($path, $filename);
         if (strlen($filename) > 0 && ($mess = self::CheckFileName($filename)) !== true) {
             $strWarning = $mess;
         }
         if ($strWarning == '') {
             $fn = $io->ExtractNameFromPath($pathto);
             if ($APPLICATION->GetFileAccessPermission(array($site, $pathto)) > "R" && ($USER->IsAdmin() || !HasScriptExtension($fn) && substr($fn, 0, 1) != "." && $io->ValidateFilenameString($fn))) {
                 if (!$io->FileExists($rootPath . $pathto) || $_REQUEST["rewrite"] == "Y") {
                     //************************** Quota **************************//
                     $bQuota = true;
                     if (COption::GetOptionInt("main", "disk_space") > 0) {
                         $bQuota = false;
                         $quota = new CDiskQuota();
                         if ($quota->checkDiskQuota(array("FILE_SIZE" => filesize($F["tmp_name"])))) {
                             $bQuota = true;
                         }
                     }
                     //************************** Quota **************************//
                     if ($bQuota) {
                         $io->Copy($F["tmp_name"], $rootPath . $pathto);
                         $flTmp = $io->GetFile($rootPath . $pathto);
                         $flTmp->MarkWritable();
                         if (COption::GetOptionInt("main", "disk_space") > 0) {
                             CDiskQuota::updateDiskQuota("file", $flTmp->GetFileSize(), "copy");
                         }
                         $buffer = 'setTimeout(function(){parent.oBXDialogControls.Uploader.OnAfterUpload("' . $filename . '", ' . ($upload_and_open == "Y" ? 'true' : 'false') . ');}, 50);';
                     } else {
                         $strWarning = $quota->LAST_ERROR;
                     }
                 } else {
                     $strWarning = GetMessage("FD_LOAD_EXIST_ALERT");
                 }
             } else {
                 $strWarning = GetMessage("FD_LOAD_DENY_ALERT");
             }
         }
     } else {
         $strWarning = GetMessage("FD_LOAD_ERROR_ALERT");
     }
     if ($strWarning != '') {
         $buffer = 'alert("' . addslashes(htmlspecialcharsex($strWarning)) . '");';
     }
     return '<script>' . $buffer . '</script>';
 }
Exemple #8
0
    function UndoNewFile($Params, $type)
    {
        global $APPLICATION;
        $documentRoot = CSite::GetSiteDocRoot($Params['site']);
        $io = CBXVirtualIo::GetInstance();
        // Delete file
        $f = $io->GetFile($Params['absPath']);
        $f->MarkWritable();
        if (COption::GetOptionInt("main", "disk_space") > 0) {
            $file_size = $f->GetFileSize();
            $quota = new CDiskQuota();
            $quota->UpdateDiskQuota("file", $file_size, "delete");
        }
        $sucess = $io->Delete($Params['absPath']);
        if (!$sucess) {
            return;
        }
        $APPLICATION->RemoveFileAccessPermission(array($Params['site'], $Params['path']));
        if (CModule::IncludeModule("search")) {
            CSearch::DeleteIndex("main", $Params['site'] . "|" . $Params['path']);
        }
        // Find and clean file from menu
        if ($Params['menu']) {
            $arMenu = CFileman::GetMenuArray($documentRoot . $Params['menu']['menuFile']);
            if (!empty($arMenu["aMenuLinks"])) {
                $found = false;
                foreach ($arMenu["aMenuLinks"] as $menuIndex => $arItem) {
                    if ($arItem[1] == $Params['menu']['menuPath'] && $arItem[0] == $Params['menu']['menuName']) {
                        unset($arMenu["aMenuLinks"][$menuIndex]);
                        $found = true;
                        break;
                    }
                }
                if ($found) {
                    CFileMan::SaveMenu(array($Params['site'], $Params['menu']['menuFile']), $arMenu["aMenuLinks"], $arMenu["sMenuTemplate"]);
                }
            }
        }
        if (isset($Params['public']) && $Params['public'] == 'Y') {
            ?>
			<script type="text/javascript">
				window.location = '<?php 
            echo CUtil::JSEscape(CHTTP::URN2URI(GetDirPath($Params['path'])));
            ?>
';
			</script>
		<?php 
        }
        $GLOBALS["CACHE_MANAGER"]->CleanDir("menu");
    }
 public function processActionGetDiskQuota()
 {
     $this->enableIgnoreQuotaError();
     $quota = CDiskQuota::GetDiskQuota();
     if ($quota === true) {
         return $this->sendResponse(array('status' => static::STATUS_UNLIMITED, 'quota' => null));
     }
     return $this->sendResponse(array('status' => static::STATUS_LIMITED, 'quota' => $quota === false ? 0 : $quota));
 }
Exemple #10
0
 function writeFile($file_name, $content)
 {
     global $USER;
     if (is_object($USER) && $USER->IsAuthorized()) {
         return;
     }
     $content_len = function_exists('mb_strlen') ? mb_strlen($content, 'latin1') : strlen($content);
     if ($content_len <= 0) {
         return;
     }
     $arHTMLPagesOptions = CHTMLPagesCache::GetOptions(true);
     if (!is_array($arHTMLPagesOptions)) {
         return;
     }
     //Let's be pessimists
     $bQuota = false;
     if (class_exists("cdiskquota")) {
         $quota = new CDiskQuota();
         if ($quota->checkDiskQuota(array("FILE_SIZE" => $content_len))) {
             $bQuota = true;
         }
     } else {
         $bQuota = true;
     }
     $arStat = CHTMLPagesCache::readStatistic();
     if ($arStat) {
         $cached_size = $arStat["FILE_SIZE"];
     } else {
         $cached_size = 0.0;
     }
     $cache_quota = doubleval($arHTMLPagesOptions["~FILE_QUOTA"]);
     if ($bQuota && $cache_quota > 0.0) {
         if ($cache_quota < $cached_size + $content_len) {
             $bQuota = false;
         }
     }
     if ($bQuota) {
         CheckDirPath($file_name);
         $written = 0;
         $tmp_filename = $file_name . md5(mt_rand()) . ".tmp";
         $file = fopen($tmp_filename, "wb");
         if ($file !== false) {
             $written = fwrite($file, $content);
             if ($written == $content_len) {
                 fclose($file);
                 if (file_exists($file_name)) {
                     unlink($file_name);
                 }
                 rename($tmp_filename, $file_name);
                 @chmod($file_name, defined("BX_FILE_PERMISSIONS") ? BX_FILE_PERMISSIONS : 0664);
                 if (class_exists("cdiskquota")) {
                     CDiskQuota::updateDiskQuota("file", $content_len, "copy");
                 }
             } else {
                 $written = 0;
                 fclose($file);
                 if (file_exists($file_name)) {
                     unlink($file_name);
                 }
                 if (file_exists($tmp_filename)) {
                     unlink($tmp_filename);
                 }
             }
         }
         $arStat = CHTMLPagesCache::writeStatistic(0, 1, 0, 0, $written);
     } else {
         //Fire cleanup
         CHTMLPagesCache::CleanAll();
         CHTMLPagesCache::writeStatistic(0, 0, 1, 0, false);
     }
 }
Exemple #11
0
 function CheckFields(&$arFields, $ID = false, $bCheckDiskQuota = true)
 {
     global $DB, $APPLICATION, $USER;
     $this->LAST_ERROR = "";
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnStartIBlockElementAdd", true);
     } else {
         $arFields["ID"] = $ID;
         $db_events = GetModuleEvents("iblock", "OnStartIBlockElementUpdate", true);
     }
     foreach ($db_events as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             break;
         }
     }
     if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ELEMENT_NAME") . "<br>";
     }
     if (isset($arFields["ACTIVE_FROM"]) && $arFields["ACTIVE_FROM"] != '' && !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANG, "FULL")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_FROM") . "<br>";
     }
     if (isset($arFields["ACTIVE_TO"]) && $arFields["ACTIVE_TO"] != '' && !$DB->IsDate($arFields["ACTIVE_TO"], false, LANG, "FULL")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_TO") . "<br>";
     }
     if (is_set($arFields, "PREVIEW_PICTURE")) {
         if (is_array($arFields["PREVIEW_PICTURE"]) && array_key_exists("bucket", $arFields["PREVIEW_PICTURE"]) && is_object($arFields["PREVIEW_PICTURE"]["bucket"])) {
             //This is trusted image from xml import
         } elseif (is_array($arFields["PREVIEW_PICTURE"])) {
             $error = CFile::CheckImageFile($arFields["PREVIEW_PICTURE"]);
             if (strlen($error) > 0) {
                 $this->LAST_ERROR .= $error . "<br>";
             } elseif (($error = CFile::checkForDb($arFields, "PREVIEW_PICTURE")) !== "") {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>" . $error . "<br>";
             }
         } elseif (intval($arFields["PREVIEW_PICTURE"]) > 0) {
             if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["PREVIEW_PICTURE"], $ID, "PREVIEW", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>";
             }
         }
     }
     if (is_set($arFields, "DETAIL_PICTURE")) {
         if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) {
             //This is trusted image from xml import
         } elseif (is_array($arFields["DETAIL_PICTURE"])) {
             $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]);
             if (strlen($error) > 0) {
                 $this->LAST_ERROR .= $error . "<br>";
             } elseif (($error = CFile::checkForDb($arFields, "DETAIL_PICTURE")) !== "") {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>" . $error . "<br>";
             }
         } elseif (intval($arFields["DETAIL_PICTURE"]) > 0) {
             if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["DETAIL_PICTURE"], $ID, "DETAIL", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>";
             }
         }
     }
     if (array_key_exists("TAGS", $arFields) && CModule::IncludeModule('search')) {
         $arFields["TAGS"] = implode(", ", tags_prepare($arFields["TAGS"]));
     }
     if ($ID === false && !is_set($arFields, "IBLOCK_ID")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
     }
     if ($ID !== false && is_set($arFields, "XML_ID") && strlen($arFields["XML_ID"]) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_EXTERNAL_CODE") . "<br>";
     }
     //Find out IBLOCK_ID from fields or from element
     $IBLOCK_ID = intval($arFields["IBLOCK_ID"]);
     if ($IBLOCK_ID <= 0) {
         $IBLOCK_ID = 0;
         $res = $DB->Query("SELECT IBLOCK_ID FROM b_iblock_element WHERE ID=" . IntVal($ID));
         if ($ar = $res->Fetch()) {
             $IBLOCK_ID = (int) $ar["IBLOCK_ID"];
         }
     }
     //Read iblock metadata
     static $IBLOCK_CACHE = array();
     if (!isset($IBLOCK_CACHE[$IBLOCK_ID])) {
         if ($IBLOCK_ID > 0) {
             $IBLOCK_CACHE[$IBLOCK_ID] = CIBlock::GetArrayByID($IBLOCK_ID);
         } else {
             $IBLOCK_CACHE[$IBLOCK_ID] = false;
         }
     }
     if ($IBLOCK_CACHE[$IBLOCK_ID]) {
         $arFields["IBLOCK_ID"] = $IBLOCK_ID;
     } else {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
     }
     if (is_set($arFields, 'IBLOCK_SECTION') && !empty($arFields['IBLOCK_SECTION'])) {
         if (!is_array($arFields['IBLOCK_SECTION'])) {
             $arFields['IBLOCK_SECTION'] = array($arFields['IBLOCK_SECTION']);
         }
         $arFields['IBLOCK_SECTION'] = array_filter($arFields['IBLOCK_SECTION']);
     }
     if ($IBLOCK_CACHE[$IBLOCK_ID]) {
         $ar = $IBLOCK_CACHE[$IBLOCK_ID]["FIELDS"];
         if (is_array($ar)) {
             $WF_PARENT_ELEMENT_ID = isset($arFields["WF_PARENT_ELEMENT_ID"]) ? intval($arFields["WF_PARENT_ELEMENT_ID"]) : 0;
             if (($WF_PARENT_ELEMENT_ID == 0 || $WF_PARENT_ELEMENT_ID == intval($ID)) && array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) > 0 && is_array($ar["CODE"]["DEFAULT_VALUE"]) && $ar["CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") {
                 $res = $DB->Query("\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_iblock_element\n\t\t\t\t\t\tWHERE IBLOCK_ID = " . $IBLOCK_ID . "\n\t\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\t\tAND WF_PARENT_ELEMENT_ID IS NULL\n\t\t\t\t\t\tAND ID <> " . intval($ID));
                 if ($res->Fetch()) {
                     $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_ELEMENT_CODE") . "<br>";
                 }
             }
             $arOldElement = false;
             foreach ($ar as $FIELD_ID => $field) {
                 if (preg_match("/^(SECTION_|LOG_)/", $FIELD_ID)) {
                     continue;
                 }
                 if ($field["IS_REQUIRED"] === "Y") {
                     switch ($FIELD_ID) {
                         case "NAME":
                         case "ACTIVE":
                         case "PREVIEW_TEXT_TYPE":
                         case "DETAIL_TEXT_TYPE":
                         case "SORT":
                             //We should never check for this fields
                             break;
                         case "IBLOCK_SECTION":
                             if ($ID === false || array_key_exists($FIELD_ID, $arFields)) {
                                 $sum = 0;
                                 if (is_array($arFields[$FIELD_ID])) {
                                     foreach ($arFields[$FIELD_ID] as $k => $v) {
                                         if (intval($v) > 0) {
                                             $sum += intval($v);
                                         }
                                     }
                                 } else {
                                     $sum = intval($arFields[$FIELD_ID]);
                                 }
                                 if ($sum <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             }
                             break;
                         case "PREVIEW_PICTURE":
                         case "DETAIL_PICTURE":
                             if ($ID !== false && !$arOldElement) {
                                 $rs = $DB->Query("SELECT PREVIEW_PICTURE, DETAIL_PICTURE from b_iblock_element WHERE ID = " . intval($ID));
                                 $arOldElement = $rs->Fetch();
                             }
                             if ($arOldElement && $arOldElement[$FIELD_ID] > 0) {
                                 //There was an picture so just check that it is not deleted
                                 if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             } else {
                                 //There was NO picture so it MUST be present
                                 if (!array_key_exists($FIELD_ID, $arFields)) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 } elseif (is_array($arFields[$FIELD_ID])) {
                                     if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) {
                                         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                     }
                                 } else {
                                     if (intval($arFields[$FIELD_ID]) <= 0) {
                                         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                     }
                                 }
                             }
                             break;
                         default:
                             if ($ID === false || array_key_exists($FIELD_ID, $arFields)) {
                                 if (is_array($arFields[$FIELD_ID])) {
                                     $val = implode("", $arFields[$FIELD_ID]);
                                 } else {
                                     $val = $arFields[$FIELD_ID];
                                 }
                                 if (strlen($val) <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             }
                             break;
                     }
                 }
             }
         }
     }
     if (array_key_exists("PROPERTY_VALUES", $arFields) && is_array($arFields["PROPERTY_VALUES"])) {
         //First "normalize" properties to form:
         //$arFields["PROPERTY_VALUES"][<PROPERTY_ID>][<PROPERTY_VALUE_ID>] => $value
         $arProperties = array();
         foreach ($arFields["PROPERTY_VALUES"] as $key => $property_values) {
             $arProperties[$key] = array();
             if (is_array($property_values)) {
                 if (array_key_exists("VALUE", $property_values)) {
                     $arProperties[$key][] = $property_values["VALUE"];
                 } elseif (array_key_exists("tmp_name", $property_values)) {
                     $arProperties[$key][] = $property_values;
                 } else {
                     foreach ($property_values as $key2 => $property_value) {
                         if (is_array($property_value) && array_key_exists("VALUE", $property_value)) {
                             //each of these may be "complex"
                             $arProperties[$key][] = $property_value["VALUE"];
                         } else {
                             //or simple
                             $arProperties[$key][] = $property_value;
                         }
                     }
                 }
             } else {
                 $arProperties[$key][] = $property_values;
             }
         }
         foreach ($arProperties as $key => $property_values) {
             $arProperty = CIBlockProperty::GetPropertyArray($key, $IBLOCK_ID);
             if ($arProperty["USER_TYPE"] != "") {
                 $arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]);
             } else {
                 $arUserType = array();
             }
             if (array_key_exists("CheckFields", $arUserType)) {
                 foreach ($property_values as $key2 => $property_value) {
                     $arError = call_user_func_array($arUserType["CheckFields"], array($arProperty, array("VALUE" => $property_value)));
                     if (is_array($arError)) {
                         foreach ($arError as $err_mess) {
                             $this->LAST_ERROR .= $err_mess . "<br>";
                         }
                     }
                 }
             }
             //Files check
             $bError = false;
             if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] == 'F') {
                 //New element
                 if ($ID === false) {
                     $bError = true;
                     foreach ($property_values as $key2 => $property_value) {
                         if (is_array($property_value) && array_key_exists("tmp_name", $property_value) && array_key_exists("size", $property_value)) {
                             if ($property_value['size'] > 0) {
                                 $bError = false;
                                 break;
                             }
                         } elseif (intval($property_value) > 0) {
                             //This is history copy of the file
                             $bError = false;
                             break;
                         }
                     }
                 } else {
                     $dbProperty = CIBlockElement::GetProperty($arProperty["IBLOCK_ID"], $ID, "sort", "asc", array("ID" => $arProperty["ORIG_ID"], "EMPTY" => "N"));
                     $bCount = 0;
                     while ($a = $dbProperty->Fetch()) {
                         if ($a["VALUE"] > 0) {
                             $bCount++;
                         }
                     }
                     foreach ($property_values as $key2 => $property_value) {
                         if (is_array($property_value)) {
                             if ($property_value['size'] > 0) {
                                 $bCount++;
                                 break;
                             } elseif ($property_value['del'] == 'Y') {
                                 $bCount--;
                             }
                         } elseif (intval($property_value) > 0) {
                             //This is history copy of the file
                             $bCount++;
                             break;
                         }
                     }
                     $bError = $bCount <= 0;
                 }
             }
             if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] != 'F') {
                 $len = 0;
                 foreach ($property_values as $key2 => $property_value) {
                     if (array_key_exists("GetLength", $arUserType)) {
                         $len += call_user_func_array($arUserType["GetLength"], array($arProperty, array("VALUE" => $property_value)));
                     } else {
                         $len += strlen($property_value);
                     }
                     if ($len > 0) {
                         break;
                     }
                 }
                 $bError = $len <= 0;
             }
             if ($bError) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_PROPERTY", array("#PROPERTY#" => $arProperty["NAME"])) . "<br>";
             }
             // check file properties for correctness
             if ($arProperty['PROPERTY_TYPE'] == 'F') {
                 $bImageOnly = False;
                 $arImageExtentions = explode(",", strtoupper(CFile::GetImageExtensions()));
                 if (strlen($arProperty["FILE_TYPE"])) {
                     $bImageOnly = True;
                     $arAvailTypes = explode(",", strtoupper($arProperty["FILE_TYPE"]));
                     foreach ($arAvailTypes as $avail_type) {
                         if (!in_array(trim($avail_type), $arImageExtentions)) {
                             $bImageOnly = False;
                             break;
                         }
                     }
                 }
                 foreach ($property_values as $key2 => $property_value) {
                     if (!is_array($property_value) && intval($property_value) > 0 && intval($arFields["WF_PARENT_ELEMENT_ID"]) > 0) {
                         if (CIBlockElement::DeleteFile($property_value, $ID, "PROPERTY", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) {
                             $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_FILE_PROPERTY") . "<br>";
                         }
                     } elseif (is_array($property_value)) {
                         if (is_object($property_value["bucket"])) {
                             //This is trusted image from xml import
                             $error = "";
                         } else {
                             if ($bImageOnly) {
                                 $error = CFile::CheckImageFile($property_value);
                             } else {
                                 $error = CFile::CheckFile($property_value, 0, false, $arProperty["FILE_TYPE"]);
                             }
                         }
                         //For user without edit php permissions
                         //we allow only pictures upload
                         if (!is_object($USER) || !$USER->IsAdmin()) {
                             if (HasScriptExtension($property_value["name"])) {
                                 $error = GetMessage("FILE_BAD_TYPE") . " (" . $property_value["name"] . ").";
                             }
                         }
                         if (strlen($error) > 0) {
                             $this->LAST_ERROR .= $error . "<br>";
                         }
                     }
                 }
             }
         }
     }
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementAdd", true);
     } else {
         $arFields["ID"] = $ID;
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementUpdate", true);
     }
     foreach ($db_events as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $APPLICATION->ThrowException("Unknown error");
                 $this->LAST_ERROR .= "Unknown error.<br>";
             }
             break;
         }
     }
     /****************************** QUOTA ******************************/
     if ($bCheckDiskQuota && empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (!$quota->checkDiskQuota($arFields)) {
             $this->LAST_ERROR = $quota->LAST_ERROR;
         }
     }
     /****************************** QUOTA ******************************/
     if (!empty($this->LAST_ERROR)) {
         return false;
     }
     return true;
 }
Exemple #12
0
    public static function InsertMainItems()
    {
        if (defined('BX_PUBLIC_MODE') && BX_PUBLIC_MODE == 1) {
            return false;
        }
        global $USER;
        if (!$USER->IsAuthorized()) {
            return false;
        }
        //Updates
        if ($USER->IsAdmin() || $USER->CanDoOperation('install_updates')) {
            $update_res = UpdateTools::GetUpdateResult();
            $updAIParams = array("TITLE" => GetMessage("top_panel_ai_updates"), "COLOR" => 'gray', "SORT" => 12);
            //update_autocheck == true and we have something to show
            if ($update_res['result'] === true && $update_res['tooltip']) {
                $updAIParams["HTML"] = $update_res['tooltip'];
                $updAIParams["FOOTER"] = '<a href="/bitrix/admin/update_system.php?lang=' . LANGUAGE_ID . '">' . GetMessage("top_panel_ai_upd_instl") . '</a>';
                $updAIParams["ALERT"] = true;
            } else {
                if ($update_res['error'] != '') {
                    $updAIParams["TITLE"] .= " - " . GetMessage("top_panel_ai_title_err");
                    $updAIParams["HTML"] = trim(self::CutErrorId($update_res['error']));
                    $updAIParams["FOOTER"] = '<a href="/bitrix/admin/update_system.php?refresh=Y&lang=' . LANGUAGE_ID . '">' . GetMessage("top_panel_ai_upd_chk") . '</a>';
                    $updAIParams["ALERT"] = true;
                } else {
                    //last update date time
                    $updateDate = COption::GetOptionString("main", "update_system_update", false);
                    // remove seconds
                    $updateDate = $updateDate ? CDatabase::FormatDate($updateDate, "DD.MM.YYYY HH:MI:SS", "DD.MM.YYYY HH:MI") : false;
                    $updAIParams["HTML"] = '<span class="adm-informer-strong-text">' . GetMessage("top_panel_ai_sys_ver") . ' ' . SM_VERSION . "</span><br>";
                    $updAIParams["HTML"] .= $updateDate ? GetMessage("top_panel_ai_upd_last") . '<br>' . $updateDate : GetMessage("top_panel_ai_upd_never");
                    $updAIParams["FOOTER"] = '<a href="/bitrix/admin/update_system.php?refresh=Y&lang=' . LANGUAGE_ID . '">' . GetMessage("top_panel_ai_upd_chk") . '</a>';
                    $updAIParams["ALERT"] = false;
                }
            }
            self::AddItem($updAIParams);
        }
        //Disk space (quota)
        $maxQuota = COption::GetOptionInt("main", "disk_space", 0) * 1048576;
        if ($maxQuota > 0) {
            $quota = new CDiskQuota();
            $free = $quota->GetDiskQuota();
            $freeMB = CFile::FormatSize($free, 1);
            $free = round($free / $maxQuota * 100);
            $qAIParams = array("TITLE" => GetMessage("top_panel_ai_used_space"), "COLOR" => "green", "ALERT" => $free < 10 ? true : false);
            $qAIParams["HTML"] = '
	<div class="adm-informer-item-section">
		<span class="adm-informer-item-l"><span class="adm-informer-strong-text">' . GetMessage("top_panel_ai_in_all") . '</span> ' . CFile::FormatSize($maxQuota, 1) . '</span>
		<span class="adm-informer-item-r"><span class="adm-informer-strong-text">' . GetMessage("top_panel_ai_in_aviable") . '</span> ' . $freeMB . '</span>
	</div>
	<div class="adm-informer-status-bar-block" >
		<div class="adm-informer-status-bar-indicator" style="width:' . (100 - $free) . '%; "></div>
		<div class="adm-informer-status-bar-text">' . (100 - $free) . '%</div>
	</div>
	<div class="adm-informer-item-section"><span class="adm-informer-strong-text">' . GetMessage("top_panel_ai_in_recomend") . '</span> ' . GetMessage("top_panel_ai_in_no") . '</div>';
            self::AddItem($qAIParams);
        }
        $rsHandlers = GetModuleEvents("main", "OnAdminInformerInsertItems");
        while ($arHandler = $rsHandlers->Fetch()) {
            ExecuteModuleEventEx($arHandler);
        }
        return count(self::$items);
    }
Exemple #13
0
	function GetPanelHtml()
	{
		global $USER, $APPLICATION, $DB;

		$hkInstance = CHotKeys::getInstance();

		if ($APPLICATION->ShowPanel === false || (!$USER->IsAuthorized() && $APPLICATION->ShowPanel !== true))
			return "";

		CTopPanel::InitPanelIcons();

		$arPanelButtons = &$APPLICATION->arPanelButtons;
		usort($arPanelButtons, array("CTopPanel", "SortButtons"));

		$bShowPanel = false;
		foreach($arPanelButtons as $key=>$arValue)
		{
			if(trim($arValue["HREF"]) <> "" || is_array($arValue["MENU"]) && !empty($arValue["MENU"]))
			{
				//we have at least one button to show
				$bShowPanel = true;
				break;
			}
		}

		if($bShowPanel == false)
		{
			$arCodes = unserialize(COption::GetOptionString("main", "show_panel_for_users"));
			if($USER->CanAccess($arCodes))
			{
				//we have settings in the main module options
				$bShowPanel = true;
			}
		}

		if ($bShowPanel == false && $APPLICATION->ShowPanel !== true)
			return "";

		$APPLICATION->PanelShowed = true;


		if ($_GET["back_url_admin"] <> "" && strpos($_GET["back_url_admin"], "/") === 0)
			$_SESSION["BACK_URL_ADMIN"] = $_GET["back_url_admin"];

		$aUserOpt = CUserOptions::GetOption("admin_panel", "settings");
		$aUserOptGlobal = CUserOptions::GetOption("global", "settings");

		$toggleModeSet = false;
		if (isset($_GET["bitrix_include_areas"]) && $_GET["bitrix_include_areas"] <> "")
		{
			$APPLICATION->SetShowIncludeAreas($_GET["bitrix_include_areas"]=="Y");
			$toggleModeSet = true;
		}

		$showMode = $APPLICATION->GetPublicShowMode();

		$params = DeleteParam(array("bitrix_include_areas", "bitrix_show_mode", "back_url_admin"));
		$href = $APPLICATION->GetCurPage();
		$hrefEnc = htmlspecialcharsbx($href);

		$toggleModeDynamic = $aUserOptGlobal['panel_dynamic_mode'] == 'Y';
		$toggleMode = $toggleModeDynamic && !$toggleModeSet
			? $aUserOpt['edit'] == 'on'
			: $APPLICATION->GetShowIncludeAreas() == 'Y';

		//Save if changed
		$old_edit = $aUserOpt['edit'];
		$aUserOpt['edit'] = $toggleMode ? 'on' : 'off';
		if($old_edit !== $aUserOpt['edit'])
			CUserOptions::SetOption('admin_panel', 'settings', $aUserOpt);

		$toggleModeLink = $hrefEnc.'?bitrix_include_areas='.($toggleMode ? 'N' : 'Y').($params<>""? "&amp;".htmlspecialcharsbx($params):"");

		$maxQuotaMB = COption::GetOptionInt("main", "disk_space", 0);
		$maxQuota = $maxQuotaMB*1048576;//*1024*1024
		if($maxQuota > 0)
		{
			$quota = new CDiskQuota();
			$free = $quota->GetDiskQuota();
			$freeMB = intval($free/1048576);
		}

		$result = CTopPanel::ShowPanelScripts(true);
		$result .= '
	<!--[if lte IE 7]>
	<style type="text/css">#bx-panel {display:none !important;}</style>
	<div id="bx-panel-error">'.GetMessage("top_panel_browser").'</div><![endif]-->
	<script type="text/javascript">BX.admin.dynamic_mode='.($toggleModeDynamic ? 'true' : 'false').'; BX.admin.dynamic_mode_show_borders = '.($toggleMode ? 'true' : 'false').';</script>
	<div style="display:none; overflow:hidden;" id="bx-panel-back"></div>
	<div id="bx-panel"'.($aUserOpt["collapsed"] == "on" ? ' class="bx-panel-folded"':'').'>
		<div id="bx-panel-top">
			<div id="bx-panel-top-gutter"></div>
			<div id="bx-panel-tabs">
	';
		$result .= '
				<a id="bx-panel-menu" href="" '.CTopPanel::AddAttrHint(GetMessage('top_panel_start_menu_tooltip_title'), GetMessage('top_panel_start_menu_tooltip')).'><span id="bx-panel-menu-icon"></span><span id="bx-panel-menu-text">'.GetMessage("top_panel_menu").'</span></a><a id="bx-panel-view-tab"><span>'.GetMessage("top_panel_site").'</span></a><a id="bx-panel-admin-tab" href="'.(
						$_SESSION["BACK_URL_ADMIN"] <> ""
						? htmlspecialcharsbx($_SESSION["BACK_URL_ADMIN"]).(strpos($_SESSION["BACK_URL_ADMIN"], "?") !== false? "&amp;":"?")
						: '/bitrix/admin/index.php?lang='.LANGUAGE_ID.'&amp;'
					).'back_url_pub='.urlencode($href.($params<>""? "?".$params:"")).'"><span>'.GetMessage("top_panel_admin").'</span></a>';

		$back_url = CUtil::JSUrlEscape(CUtil::addslashes($href.($params<>""? "?".$params:"")));
		$arStartMenuParams = array(
			'DIV' => 'bx-panel-menu',
			'ACTIVE_CLASS' => 'bx-pressed',
			'MENU_URL' => '/bitrix/admin/get_start_menu.php?lang='.LANGUAGE_ID.'&back_url_pub='.urlencode($back_url).'&'.bitrix_sessid_get(),
			'MENU_PRELOAD' => ($aUserOptGlobal["start_menu_preload"] == 'Y')
		);

		$result .= '<script type="text/javascript">new BX.COpener('.CUtil::PhpToJsObject($arStartMenuParams).')</script>';

		$Execs=$hkInstance->GetCodeByClassName("top_panel_menu",GetMessage("top_panel_menu"));
		$result .=$hkInstance->PrintJSExecs($Execs);
		$Execs=$hkInstance->GetCodeByClassName("top_panel_admin",GetMessage("top_panel_admin"));
		$result .=$hkInstance->PrintJSExecs($Execs);

		$informerItemsCount = CAdminInformer::InsertMainItems();

		if($informerItemsCount>0)
			$result .= '<a class="adm-header-notif-block" id="adm-header-notif-block" onclick="BX.adminInformer.Toggle(this);"><span class="adm-header-notif-icon"></span><span id="adm-header-notif-counter" class="adm-header-notif-counter">'.CAdminInformer::$alertCounter.'</span></a>';

		if ($USER->CanDoOperation("cache_control"))
		{
			$result .= '<a id="bx-panel-clear-cache" href="" onclick="BX.clearCache(); return false;"><span id="bx-panel-clear-cache-icon"></span><span id="bx-panel-clear-cache-text">'.GetMessage("top_panel_cache_new_tooltip_title").'</span></a>';
		}

		$result .= '
			</div>
			<div id="bx-panel-userinfo">
	';

		$bCanProfile = $USER->CanDoOperation('view_own_profile') || $USER->CanDoOperation('edit_own_profile');

		$userName = CUser::FormatName(
			CSite::GetNameFormat(false),
			array(
				"NAME"	=> $USER->GetFirstName(),
				"LAST_NAME"	=> $USER->GetLastName(),
				"SECOND_NAME" => $USER->GetSecondName(),
				"LOGIN"		=> $USER->GetLogin()
			),
			$bUseLogin = true,
			$bHTMLSpec = true
		);

		if ($bCanProfile)
		{
			$result .= '<a href="/bitrix/admin/user_edit.php?lang='.LANGUAGE_ID.'&ID='.$USER->GetID().'" id="bx-panel-user" '.CTopPanel::AddAttrHint(GetMessage('top_panel_profile_tooltip')).'><span id="bx-panel-user-icon"></span><span id="bx-panel-user-text">'.$userName.'</span></a>';
		}
		else
		{
			$result .= '<a id="bx-panel-user"><span id="bx-panel-user-icon"></span><span id="bx-panel-user-text">'.$userName.'</span></a>';
		}

		$result .= '<a href="'.$hrefEnc.'?logout=yes'.htmlspecialcharsbx(($s=DeleteParam(array("logout"))) == ""? "":"&".$s).'" id="bx-panel-logout" '.CTopPanel::AddAttrHint(GetMessage('top_panel_logout_tooltip').$hkInstance->GetTitle("bx-panel-logout",true)).'>'.GetMessage("top_panel_logout").'</a>';

		$toggleCaptionOn = '<span id="bx-panel-toggle-caption-mode-on">'.GetMessage("top_panel_on").'</span>';
		$toggleCaptionOff = '<span id="bx-panel-toggle-caption-mode-off">'.GetMessage("top_panel_off").'</span>';
		$toggleCaptions = $toggleMode ? $toggleCaptionOn.$toggleCaptionOff : $toggleCaptionOff.$toggleCaptionOn;
		$toogle = '<a href="'.$toggleModeLink.'" id="bx-panel-toggle" class="bx-panel-toggle'.($toggleMode ? '-on' : '-off').'"'.($toggleModeDynamic ? '' : ' '.CTopPanel::AddAttrHint(GetMessage("top_panel_edit_mode_new_tooltip_title"), GetMessage('top_panel_toggle_tooltip').$hkInstance->GetTitle("bx-panel-small-toggle",true))).'><span id="bx-panel-switcher-gutter-left"></span><span id="bx-panel-toggle-indicator"><span id="bx-panel-toggle-icon"></span><span id="bx-panel-toggle-icon-overlay"></span></span><span class="bx-panel-break"></span><span id="bx-panel-toggle-caption">'.GetMessage("top_panel_edit_mode_new").'</span><span class="bx-panel-break"></span><span id="bx-panel-toggle-caption-mode">'.$toggleCaptions.'</span><span id="bx-panel-switcher-gutter-right"></span></a>';
		if ($aUserOpt["collapsed"] == "on")
			$result .= $toogle;

		$result .= '<a href="" id="bx-panel-expander" '.CTopPanel::AddAttrHint(GetMessage("top_panel_expand_tooltip_title"), GetMessage("top_panel_expand_tooltip").$hkInstance->GetTitle("bx-panel-expander",true)).'><span id="bx-panel-expander-text">'.GetMessage("top_panel_expand").'</span><span id="bx-panel-expander-arrow"></span></a>';

		if($hkInstance->IsActive())
		{
			$result .= '<a id="bx-panel-hotkeys" href="javascript:void(0)" onclick="BXHotKeys.ShowSettings();" '.CTopPanel::AddAttrHint(GetMessage("HK_PANEL_TITLE").$hkInstance->GetTitle("bx-panel-hotkeys",true)).'></a>';
		}

		$result .= '<a href="javascript:void(0)" id="bx-panel-pin"'.($aUserOpt['fix'] == 'on' ? ' class="bx-panel-pin-fixed"' : '').' '.CTopPanel::AddAttrHint(GetMessage('top_panel_pin_tooltip')).'></a>';

		$Execs	=	$hkInstance->GetCodeByClassName("bx-panel-logout",GetMessage('top_panel_logout_tooltip'));
		$result .=	$hkInstance->PrintJSExecs($Execs);
		$Execs	=	$hkInstance->GetCodeByClassName("bx-panel-small-toggle",GetMessage("top_panel_edit_mode_new_tooltip_title"),'location.href="'.$toggleModeLink.'";');
		$result .=	$hkInstance->PrintJSExecs($Execs);
		$Execs	=	$hkInstance->GetCodeByClassName("bx-panel-expander",GetMessage("top_panel_expand_tooltip_title")."/".GetMessage("top_panel_collapse_tooltip_title"));
		$result .=	$hkInstance->PrintJSExecs($Execs);

		$result .= '
			</div>
		</div>
	';


	/* BUTTONS */
		$result .= '<div id="bx-panel-site-toolbar"><div id="bx-panel-buttons-gutter"></div><div id="bx-panel-switcher">';

		if ($aUserOpt["collapsed"] != "on")
			$result .= $toogle;

		$result .= '<a href="" id="bx-panel-hider" '.CTopPanel::AddAttrHint(GetMessage("top_panel_collapse_tooltip_title"), GetMessage("top_panel_collapse_tooltip").$hkInstance->GetTitle("bx-panel-expander",true)).'>'.GetMessage("top_panel_collapse").'<span id="bx-panel-hider-arrow"></span></a>';

		$result .= '</div><div id="bx-panel-buttons"><div id="bx-panel-buttons-inner">';

		$main_sort = "";
		$last_btn_type = '';
		$last_btn_small_cnt = 0;

		$result .= '<span class="bx-panel-button-group">';
		foreach($arPanelButtons as $key=>$arButton)
		{
			$result.= $hkInstance->PrintTPButton($arButton);

			if($main_sort != $arButton["MAIN_SORT"] && $main_sort<>"")
			{
				$result .= '</span><span class="bx-panel-button-separator"></span><span class="bx-panel-button-group">';
				$last_btn_small_cnt = 0;
			}


			$arButton['TYPE'] = $arButton['TYPE'] == 'BIG' ? 'BIG' : 'SMALL';

			//very old behaviour
			if(is_set($arButton, "SRC_0"))
				$arButton["SRC"] = $arButton["SRC_0"];

			$arButton['HREF'] = trim($arButton['HREF']);
			$bHasAction = $arButton['HREF'] != '';

			if (array_key_exists("RESORT_MENU", $arButton) && $arButton["RESORT_MENU"] === true && is_array($arButton['MENU']) && !empty($arButton['MENU']))
				usort($arButton['MENU'], array("CTopPanel", "SortButtonMenu"));

			$bHasMenu = is_array($arButton['MENU']) && count($arButton['MENU']) > 0;

			if ($bHasMenu && !$bHasAction)
			{
				foreach ($arButton['MENU'] as $arItem)
				{
					if ($arItem['DEFAULT'])
					{
						$arButton['HREF'] = $arItem['HREF'];
						$bHasAction = true;
					}
				}
			}

			if ($last_btn_type != '' && $arButton['TYPE'] != $last_btn_type && $main_sort == $arButton["MAIN_SORT"])
			{
				$result .= '</span><span class="bx-panel-button-group">';
				$last_btn_small_cnt = 0;
			}

			if ($bHasAction && substr(strtolower($arButton['HREF']), 0, 11) == 'javascript:')
			{
				$arButton['ONCLICK'] = substr($arButton['HREF'], 11);
				$arButton['HREF'] = 'javascript:void(0)';
			}

			if ($arButton['HINT'])
			{
				if ($arButton['HINT']['ID'])
				{
					$hintOptions = CUtil::GetPopupOptions($arButton['HINT']['ID']);

					if($hintOptions['display'] == 'off')
					{
						unset($arButton['HINT']);
					}
				}

				if ($arButton['HINT'])
					unset($arButton['ALT']);

				if ($bHasMenu && !$arButton['HINT_MENU'])
					$arButton['HINT']['TARGET'] = 'parent';
			}

			$hkInstance = CHotKeys::getInstance();

			switch ($arButton['TYPE'])
			{
				case 'SMALL':
					if ($last_btn_small_cnt >= 3 && $main_sort == $arButton["MAIN_SORT"])
					{
						$result .= '</span><span class="bx-panel-button-group">';
						$last_btn_small_cnt = 0;
					}
					elseif ($last_btn_small_cnt > 0)
					{
						$result .= '<span class="bx-panel-break"></span>';
					}

					$result .= '<span class="bx-panel-small-button"><span class="bx-panel-small-button-inner">';

					$button_icon = '<span class="bx-panel-small-button-icon'.($arButton['ICON'] ? ' '.$arButton['ICON'] : '').'"'.($arButton['SRC'] ? ' style="background: scroll transparent url('.htmlspecialcharsbx($arButton['SRC']).') no-repeat center center !important;"' : '').'></span>';
					$button_text = '<span class="bx-panel-small-button-text">'.htmlspecialcharsbx($arButton['TEXT']).'</span>';

					if ($bHasAction)
					{
						$result .= '<a href="'.htmlspecialcharsbx($arButton['HREF']).'" onclick="'.htmlspecialcharsbx($arButton['ONCLICK']).';BX.removeClass(this.parentNode.parentNode, \'bx-panel-small-button'.($bHasMenu ? '-text' : '').'-active\')" id="bx_topmenu_btn_'.$key.'"'.($arButton['ALT'] ? ' title="'.htmlspecialcharsbx($arButton['ALT']).$hkInstance->GetTitle("bx_topmenu_btn_".$key).'"' : '"'.$hkInstance->GetTitle("bx_topmenu_btn_".$key).'"').'>'.$button_icon.$button_text.'</a>';

						$result .= '<script type="text/javascript">BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'\', TYPE: \'SMALL\', ACTIVE_CSS: \'bx-panel-small-button'.($bHasMenu ? '-text' : '').'-active\', HOVER_CSS: \'bx-panel-small-button'.($bHasMenu ? '-text' : '').'-hover\''.($arButton['HINT'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT']) : '').'})</script>';
						if ($bHasMenu)
						{
							$result .= '<a href="javascript:void(0)" class="bx-panel-small-button-arrow" id="bx_topmenu_btn_'.$key.'_menu"><span class="bx-panel-small-button-arrow"></span></a>';
							$result .= '<script type="text/javascript">BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'_menu\', TYPE: \'SMALL\', MENU: '.CUtil::PhpToJsObject($arButton['MENU']).', ACTIVE_CSS: \'bx-panel-small-button-arrow-active\', HOVER_CSS: \'bx-panel-small-button-arrow-hover\''.($arButton['HINT_MENU'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT_MENU']) : '').'})</script>';
						}
					}
					elseif ($bHasMenu)
					{
						$result .= '<a href="javascript:void(0)" id="bx_topmenu_btn_'.$key.'"'.($arButton['ALT'] ? ' title="'.htmlspecialcharsbx($arButton['ALT']).'"' : '').'>'.$button_icon.$button_text.'<span class="bx-panel-small-single-button-arrow"></span></a>';
						$result .= '<script type="text/javascript">BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'\', TYPE: \'SMALL\', MENU: '.CUtil::PhpToJsObject($arButton['MENU']).', ACTIVE_CSS: \'bx-panel-small-button-active\', HOVER_CSS: \'bx-panel-small-button-hover\''.($arButton['HINT'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT']) : '').'})</script>';
					}

					$result .= '</span></span>';

					$last_btn_small_cnt++;

				break;

				case 'BIG':
					$last_btn_small_cnt = 0;

					$result .= '<span class="bx-panel-button"><span class="bx-panel-button-inner">';

					$button_icon = '<span class="bx-panel-button-icon'.($arButton['ICON'] ? ' '.$arButton['ICON'] : '').'"'.($arButton['SRC'] ? ' style="background: scroll transparent url('.htmlspecialcharsbx($arButton['SRC']).') no-repeat center center !important;"' : '').'></span>';


					if ($bHasAction && $bHasMenu)
					{
						$button_text = '<span class="bx-panel-button-text">'.str_replace('#BR#', '<span class="bx-panel-break"></span>', $arButton['TEXT']).'&nbsp;<span class="bx-panel-button-arrow"></span></span>';
						$result .= '<a href="'.htmlspecialcharsbx($arButton['HREF']).'" onclick="'.htmlspecialcharsbx($arButton['ONCLICK']).';BX.removeClass(this.parentNode.parentNode, \'bx-panel-button-icon-active\');" id="bx_topmenu_btn_'.$key.'"'.($arButton['ALT'] ? ' title="'.htmlspecialcharsbx($arButton['ALT']).'"' : '').'>'.$button_icon.'</a><a id="bx_topmenu_btn_'.$key.'_menu" href="javascript:void(0)">'.$button_text.'</a>';
						$result .= '<script type="text/javascript">
	BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'\', TYPE: \'BIG\', ACTIVE_CSS: \'bx-panel-button-icon-active\', HOVER_CSS: \'bx-panel-button-icon-hover\''.($arButton['HINT'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT']) : '').'}); BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'_menu\', TYPE: \'BIG\', MENU: '.CUtil::PhpToJsObject($arButton['MENU']).', ACTIVE_CSS: \'bx-panel-button-text-active\', HOVER_CSS: \'bx-panel-button-text-hover\''.($arButton['HINT_MENU'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT_MENU']) : '').'})
	</script>';
					}
					else if ($bHasAction)
					{
						$button_text = '<span class="bx-panel-button-text">'.str_replace('#BR#', '<span class="bx-panel-break"></span>', $arButton['TEXT']).'</span>';

						$result .= '<a href="'.htmlspecialcharsbx($arButton['HREF']).'" onclick="'.htmlspecialcharsbx($arButton['ONCLICK']).';BX.removeClass(this.parentNode.parentNode, \'bx-panel-button-active\');" id="bx_topmenu_btn_'.$key.'"'.($arButton['ALT'] ? ' title="'.htmlspecialcharsbx($arButton['ALT']).'"' : '').'>'.$button_icon.$button_text.'</a>';

						$result .= '<script type="text/javascript">BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'\', TYPE: \'BIG\', ACTIVE_CSS: \'bx-panel-button-active\', HOVER_CSS: \'bx-panel-button-hover\''.($arButton['HINT'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT']) : '').'});</script>';

					}
					else // if $bHasMenu
					{
						$button_text = '<span class="bx-panel-button-text">'.str_replace('#BR#', '<span class="bx-panel-break"></span>', $arButton['TEXT']).'&nbsp;<span class="bx-panel-button-arrow"></span></span>';

						$result .= '<a href="javascript:void(0)" id="bx_topmenu_btn_'.$key.'_menu">'.$button_icon.$button_text.'</a>';

						$result .= '<script type="text/javascript">BX.admin.panel.RegisterButton({ID: \'bx_topmenu_btn_'.$key.'_menu\', TYPE: \'BIG\', MENU: '.CUtil::PhpToJsObject($arButton['MENU']).', ACTIVE_CSS: \'bx-panel-button-active\', HOVER_CSS: \'bx-panel-button-hover\''.($arButton['HINT'] ? ', HINT: '.CUtil::PhpToJsObject($arButton['HINT']) : '').'});</script>';
					}

					$result .= '</span></span>';
				break;
			}

			$main_sort = $arButton["MAIN_SORT"];
			$last_btn_type = $arButton['TYPE'];
		}
		$result .= '</span>';

		$result .= '</div>
			</div>
		</div>';

		if ($USER->IsAdmin())
			$result .= CAdminNotify::GetHtml();

		$result .= '
	</div>
	';

		$result .= '<script type="text/javascript">
		BX.admin.panel.state = {
			fixed: '.($aUserOpt["fix"] == "on" ? 'true' : 'false').',
			collapsed: '.($aUserOpt["collapsed"] == "on" ? 'true' : 'false').'
		}
		</script>';

		//start menu preload
		// if($aUserOptGlobal["start_menu_preload"] == 'Y')
		// 	$result .= '<script type="text/javascript">BX.ready(function(){jsStartMenu.PreloadMenu(\''.CUtil::JSEscape($href.($params<>""? "?".$params:"")).'\');});</script>';

		//show script to play sound
		$result .= $GLOBALS["adminPage"]->ShowSound();

		return $result;
	}
Exemple #14
0
 private function getDiskSpace()
 {
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $freeSpace = CDiskQuota::GetDiskQuota();
     return array($freeSpace === false ? 0 : $freeSpace, (double) COption::GetOptionInt('main', 'disk_space', 0) * 1024 * 1024);
 }
Exemple #15
0
		$f = $io->GetFile($abs_path);
		$arUndoParams = array(
			'module' => 'fileman',
			'undoType' => 'delete_menu',
			'undoHandler' => 'CFileman::UndoFileDelete',
			'arContent' => array(
				'site' => $site,
				'path' => $menufilename,
				'content' => $f->GetContents(),
				'perm' => CFileMan::FetchFileAccessPerm($arPath_m, true),
			)
		);

		if (COption::GetOptionInt("main", "disk_space") > 0)
		{
			$quota = new CDiskQuota();
			$quota->UpdateDiskQuota("file", $f->GetFileSize(), "delete");
		}

		$f->MarkWritable();
		$success = $io->Delete($abs_path);

		if(COption::GetOptionString($module_id, "log_menu", "Y")=="Y")
		{
			$mt = COption::GetOptionString("fileman", "menutypes", $default_value, $site);
			$mt = unserialize(str_replace("\\", "", $mt));
			$res_log['menu_name'] = $mt[$name];
			$res_log['path'] = substr($path, 1);
			CEventLog::Log(
				"content",
				"MENU_DELETE",
	private static function onEpilogHtmlCache()
	{
		global $USER;

		$bAutorized = is_object($USER) && $USER->IsAuthorized();
		if(!$bAutorized && defined("HTML_PAGES_FILE"))
		{
			@setcookie(session_name(), "", time()-360000, "/");
		}

		$bExcludeByFile = $_SERVER["SCRIPT_NAME"] == "/bitrix/admin/get_start_menu.php";

		$posts = 0;
		$bytes = 0.0;
		$all_clean = false;

		//Check if modifyng action happend
		if(($_SERVER["REQUEST_METHOD"] === "POST") || ($bAutorized && check_bitrix_sessid() && !$bExcludeByFile))
		{
			//if it was admin post
			if(strncmp($_SERVER["REQUEST_URI"], "/bitrix/", 8) === 0)
			{
				//Then will clean all the cache
				$bytes = \Bitrix\Main\Data\StaticHtmlFileStorage::deleteRecursive("/");
				$all_clean = true;
			}
			//check if it was SEF post
			elseif(array_key_exists("SEF_APPLICATION_CUR_PAGE_URL", $_REQUEST) && file_exists($_SERVER['DOCUMENT_ROOT']."/urlrewrite.php"))
			{
				$arUrlRewrite = array();
				include($_SERVER['DOCUMENT_ROOT']."/urlrewrite.php");
				foreach($arUrlRewrite as $val)
				{
					if(preg_match($val["CONDITION"], $_SERVER["REQUEST_URI"]) > 0)
					{
						if (strlen($val["RULE"]) > 0)
							$url = preg_replace($val["CONDITION"], (StrLen($val["PATH"]) > 0 ? $val["PATH"]."?" : "").$val["RULE"], $_SERVER["REQUEST_URI"]);
						else
							$url = $val["PATH"];

						$pos=strpos($url, "?");
						if($pos !== false)
						{
							$url = substr($url, 0, $pos);
						}
						$url = substr($url, 0, strrpos($url, "/")+1);
						$bytes = \Bitrix\Main\Data\StaticHtmlFileStorage::deleteRecursive($url);
						break;
					}
				}
			}
			//public page post
			else
			{
				$folder = substr($_SERVER["REQUEST_URI"], 0, strrpos($_SERVER["REQUEST_URI"], "/"));
				$bytes = \Bitrix\Main\Data\StaticHtmlFileStorage::deleteRecursive($folder);
			}
			$posts++;
		}

		if($bytes > 0.0 && class_exists("cdiskquota"))
		{
			CDiskQuota::updateDiskQuota("file", $bytes, "delete");
		}

		if($posts || $bytes)
		{
			self::writeStatistic(
				0, //hit
				0, //miss
				0, //quota
				$posts, //posts
				($all_clean? false: -$bytes) //files
			);
		}
	}
Exemple #17
0
	/**
	 * Update disk quota and cache statistic
	 * @param float $bytes positive or negative value
	 */
	public static function updateQuota($bytes)
	{
		if ($bytes == 0.0)
		{
			return;
		}

		if (class_exists("cdiskquota"))
		{
			CDiskQuota::updateDiskQuota("file", abs($bytes), $bytes > 0.0 ? "copy" : "delete");
		}

		CHTMLPagesCache::writeStatistic(0, 0, 0, 0, $bytes);
	}
Exemple #18
0
 function ResizeImageGet($file, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, $bInitSizes = false, $arFilters = false, $bImmediate = false, $jpgQuality = false)
 {
     if (!is_array($file) && intval($file) > 0) {
         $file = CFile::GetFileArray($file);
     }
     if (!is_array($file) || !array_key_exists("FILE_NAME", $file) || strlen($file["FILE_NAME"]) <= 0) {
         return false;
     }
     if ($resizeType != BX_RESIZE_IMAGE_EXACT && $resizeType != BX_RESIZE_IMAGE_PROPORTIONAL_ALT) {
         $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL;
     }
     if (!is_array($arSize)) {
         $arSize = array();
     }
     if (!array_key_exists("width", $arSize) || intval($arSize["width"]) <= 0) {
         $arSize["width"] = 0;
     }
     if (!array_key_exists("height", $arSize) || intval($arSize["height"]) <= 0) {
         $arSize["height"] = 0;
     }
     $arSize["width"] = intval($arSize["width"]);
     $arSize["height"] = intval($arSize["height"]);
     $uploadDirName = COption::GetOptionString("main", "upload_dir", "upload");
     $imageFile = "/" . $uploadDirName . "/" . $file["SUBDIR"] . "/" . $file["FILE_NAME"];
     $arImageSize = false;
     $bFilters = is_array($arFilters) && !empty($arFilters);
     if (($arSize["width"] <= 0 || $arSize["width"] >= $file["WIDTH"]) && ($arSize["height"] <= 0 || $arSize["height"] >= $file["HEIGHT"])) {
         if ($bFilters) {
             //Only filters. Leave size unchanged
             $arSize["width"] = $file["WIDTH"];
             $arSize["height"] = $file["HEIGHT"];
             $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL;
         } else {
             global $arCloudImageSizeCache;
             $arCloudImageSizeCache[$file["SRC"]] = array($file["WIDTH"], $file["HEIGHT"]);
             return array("src" => $file["SRC"], "width" => intval($file["WIDTH"]), "height" => intval($file["HEIGHT"]), "size" => $file["FILE_SIZE"]);
         }
     }
     $io = CBXVirtualIo::GetInstance();
     $cacheImageFile = "/" . $uploadDirName . "/resize_cache/" . $file["SUBDIR"] . "/" . $arSize["width"] . "_" . $arSize["height"] . "_" . $resizeType . (is_array($arFilters) ? md5(serialize($arFilters)) : "") . "/" . $file["FILE_NAME"];
     $cacheImageFileCheck = $cacheImageFile;
     if ($file["CONTENT_TYPE"] == "image/bmp") {
         $cacheImageFileCheck .= ".jpg";
     }
     static $cache = array();
     $cache_id = $cacheImageFileCheck;
     if (isset($cache[$cache_id])) {
         return $cache[$cache_id];
     } elseif (!file_exists($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"] . $cacheImageFileCheck))) {
         /****************************** QUOTA ******************************/
         $bDiskQuota = true;
         if (COption::GetOptionInt("main", "disk_space") > 0) {
             $quota = new CDiskQuota();
             $bDiskQuota = $quota->checkDiskQuota($file);
         }
         /****************************** QUOTA ******************************/
         if ($bDiskQuota) {
             if (!is_array($arFilters)) {
                 $arFilters = array(array("name" => "sharpen", "precision" => 15));
             }
             $sourceImageFile = $_SERVER["DOCUMENT_ROOT"] . $imageFile;
             $cacheImageFileTmp = $_SERVER["DOCUMENT_ROOT"] . $cacheImageFile;
             $bNeedResize = true;
             $callbackData = null;
             foreach (GetModuleEvents("main", "OnBeforeResizeImage", true) as $arEvent) {
                 if (ExecuteModuleEventEx($arEvent, array($file, array($arSize, $resizeType, array(), false, $arFilters, $bImmediate), &$callbackData, &$bNeedResize, &$sourceImageFile, &$cacheImageFileTmp))) {
                     break;
                 }
             }
             if ($bNeedResize && CFile::ResizeImageFile($sourceImageFile, $cacheImageFileTmp, $arSize, $resizeType, array(), $jpgQuality, $arFilters)) {
                 $cacheImageFile = substr($cacheImageFileTmp, strlen($_SERVER["DOCUMENT_ROOT"]));
                 /****************************** QUOTA ******************************/
                 if (COption::GetOptionInt("main", "disk_space") > 0) {
                     CDiskQuota::updateDiskQuota("file", filesize($io->GetPhysicalName($cacheImageFileTmp)), "insert");
                 }
                 /****************************** QUOTA ******************************/
             } else {
                 $cacheImageFile = $imageFile;
             }
             foreach (GetModuleEvents("main", "OnAfterResizeImage", true) as $arEvent) {
                 if (ExecuteModuleEventEx($arEvent, array($file, array($arSize, $resizeType, array(), false, $arFilters), &$callbackData, &$cacheImageFile, &$cacheImageFileTmp, &$arImageSize))) {
                     break;
                 }
             }
         } else {
             $cacheImageFile = $imageFile;
         }
         $cacheImageFileCheck = $cacheImageFile;
     }
     if ($bInitSizes && !is_array($arImageSize)) {
         $arImageSize = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $cacheImageFileCheck);
         $f = $io->GetFile($_SERVER["DOCUMENT_ROOT"] . $cacheImageFileCheck);
         $arImageSize[2] = $f->GetFileSize();
     }
     $cache[$cache_id] = array("src" => $cacheImageFileCheck, "width" => intval($arImageSize[0]), "height" => intval($arImageSize[1]), "size" => $arImageSize[2]);
     return $cache[$cache_id];
 }
Exemple #19
0
 function CheckFields(&$arFields, $ID = false)
 {
     global $DB, $APPLICATION;
     $this->LAST_ERROR = "";
     if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION") . "<br>";
     }
     if (is_array($arFields["PICTURE"]) && array_key_exists("bucket", $arFields["PICTURE"]) && is_object($arFields["PICTURE"]["bucket"])) {
         //This is trusted image from xml import
     } elseif (isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]) && isset($arFields["PICTURE"]["name"])) {
         $error = CFile::CheckImageFile($arFields["PICTURE"]);
         if (strlen($error) > 0) {
             $this->LAST_ERROR .= $error . "<br>";
         }
     }
     if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) {
         //This is trusted image from xml import
     } elseif (isset($arFields["DETAIL_PICTURE"]) && is_array($arFields["DETAIL_PICTURE"]) && isset($arFields["DETAIL_PICTURE"]["name"])) {
         $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]);
         if (strlen($error) > 0) {
             $this->LAST_ERROR .= $error . "<br>";
         }
     }
     $arIBlock = false;
     $arThis = false;
     if ($ID === false) {
         if (!array_key_exists("IBLOCK_ID", $arFields)) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
         } else {
             $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]);
             if (!$arIBlock) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
             }
         }
     } else {
         $rsThis = $DB->Query("SELECT ID, IBLOCK_ID, DETAIL_PICTURE, PICTURE FROM b_iblock_section WHERE ID = " . intval($ID));
         $arThis = $rsThis->Fetch();
         if (!$arThis) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_ID", array("#ID#" => intval($ID))) . "<br>";
         } else {
             $arIBlock = CIBlock::GetArrayByID($arThis["IBLOCK_ID"]);
             if (!$arIBlock) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
             }
         }
     }
     $arParent = false;
     $IBLOCK_SECTION_ID = isset($arFields["IBLOCK_SECTION_ID"]) ? intval($arFields["IBLOCK_SECTION_ID"]) : 0;
     if ($IBLOCK_SECTION_ID > 0 && strlen($this->LAST_ERROR) <= 0) {
         $rsParent = $DB->Query("SELECT ID, IBLOCK_ID FROM b_iblock_section WHERE ID = " . $IBLOCK_SECTION_ID);
         $arParent = $rsParent->Fetch();
         if (!$arParent) {
             $this->LAST_ERROR = GetMessage("IBLOCK_BAD_BLOCK_SECTION_PARENT") . "<br>";
         }
     }
     if ($arParent && $arIBlock) {
         if ($arParent["IBLOCK_ID"] != $arIBlock["ID"]) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_ID_PARENT") . "<br>";
         }
     }
     if ($arParent && strlen($this->LAST_ERROR) <= 0) {
         $rch = $DB->Query("\n\t\t\t\tSELECT 'x'\n\t\t\t\tFROM\n\t\t\t\t\tb_iblock_section bsto\n\t\t\t\t\t,b_iblock_section bsfrom\n\t\t\t\tWHERE\n\t\t\t\t\tbsto.ID = " . $arParent["ID"] . "\n\t\t\t\t\tAND bsfrom.ID = " . intval($ID) . "\n\t\t\t\t\tAND bsto.LEFT_MARGIN >= bsfrom.LEFT_MARGIN\n\t\t\t\t\tAND bsto.LEFT_MARGIN <= bsfrom.RIGHT_MARGIN\n\t\t\t");
         if ($rch->Fetch()) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_RECURSE") . "<br>";
         }
     }
     if ($arIBlock) {
         if (array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) && is_array($arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]) && $arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") {
             $res = $DB->Query("\n\t\t\t\t\tSELECT ID\n\t\t\t\t\tFROM b_iblock_section\n\t\t\t\t\tWHERE IBLOCK_ID = " . $arIBlock["ID"] . "\n\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\tAND ID <> " . intval($ID));
             if ($res->Fetch()) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_SECTION_CODE") . "<br>";
             }
         }
         foreach ($arIBlock["FIELDS"] as $FIELD_ID => $field) {
             if (!preg_match("/^SECTION_(.+)\$/", $FIELD_ID, $match)) {
                 continue;
             }
             $FIELD_ID = $match[1];
             if ($field["IS_REQUIRED"] === "Y") {
                 switch ($FIELD_ID) {
                     case "NAME":
                     case "DESCRIPTION_TYPE":
                         //We should never check for this fields
                         break;
                     case "PICTURE":
                         $field["NAME"] = GetMessage("IBLOCK_FIELD_PICTURE");
                     case "DETAIL_PICTURE":
                         if ($arThis && $arThis[$FIELD_ID] > 0) {
                             //There was an picture so just check that it is not deleted
                             if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") {
                                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                             }
                         } else {
                             //There was NO picture so it MUST be present
                             if (!array_key_exists($FIELD_ID, $arFields)) {
                                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                             } elseif (is_array($arFields[$FIELD_ID])) {
                                 if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             } else {
                                 if (intval($arFields[$FIELD_ID]) <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             }
                         }
                         break;
                     default:
                         if ($ID === false || array_key_exists($FIELD_ID, $arFields)) {
                             if (is_array($arFields[$FIELD_ID])) {
                                 $val = implode("", $arFields[$FIELD_ID]);
                             } else {
                                 $val = $arFields[$FIELD_ID];
                             }
                             if (strlen($val) <= 0) {
                                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                             }
                         }
                         break;
                 }
             }
         }
     }
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionAdd");
     } else {
         $arFields["ID"] = $ID;
         $arFields["IBLOCK_ID"] = $arIBlock["ID"];
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionUpdate");
     }
     /****************************** QUOTA ******************************/
     if (empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (!$quota->checkDiskQuota($arFields)) {
             $this->LAST_ERROR = $quota->LAST_ERROR;
         }
     }
     /****************************** QUOTA ******************************/
     while ($arEvent = $db_events->Fetch()) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $APPLICATION->ThrowException("Unknown error");
                 $this->LAST_ERROR .= "Unknown error.<br>";
             }
             break;
         }
     }
     if (strlen($this->LAST_ERROR) > 0) {
         return false;
     }
     return true;
 }
Exemple #20
0
							if($obUpload->Finish())
							{
								$NS['pos'] += $file_size;
								$oBucket = new CCloudStorageBucket($NS['BUCKET_ID']);
								$oBucket->IncFileCounter($file_size);

								if (file_exists($arc_name = CTar::getNextName($NS['arc_name'])))
									$NS['arc_name'] = $arc_name;
								else
								{
									$name = preg_replace('#\.[0-9]+$#','',$NS['arc_name']);
									while(file_exists($name))
									{
										$size = filesize($name);
										if (unlink($name) && IntOption("disk_space") > 0)
											CDiskQuota::updateDiskQuota("file",$size , "del");
										$name = CTar::getNextName($name);
									}

									$NS["step"]++;
								}
							}
							else
							{
								$obUpload->Delete();
								RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND").basename($NS['arc_name']));
							}
						} // partial
						else
							$pos += $NS['pos'];
					}
 function BaseCheckFields($val)
 {
     $arErrors = array();
     if (!is_array($val)) {
         $val = array();
     }
     // Check uploaded file
     if ($val["B_NEW_FILE"] != "N" && isset($val["FILE"])) {
         if ($val["FILE"]["error"] == 1 || $val["FILE"]["error"] == 2) {
             $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_SIZE_ERROR", array('#FILE_NAME#' => $pathto)) . "\n";
         }
         if (strlen($val["FILE"]["tmp_name"]) > 0) {
             $name = $val["FILE"]["name"];
             $name = preg_replace("/[^a-zA-Z0-9_:\\.]/is", "_", $name);
             $ext = GetFileExtension($name);
             if (strlen($ext) == 0 || HasScriptExtension($name) || substr($name, 0, 1) == ".") {
                 $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_INCORRECT_EXT", array("#EXT#" => strtoupper($ext)));
             } elseif (!is_uploaded_file($val["FILE"]["tmp_name"])) {
                 $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_UPLOAD_ERROR");
             } else {
                 $quota = new CDiskQuota();
                 if (!$quota->checkDiskQuota(array("FILE_SIZE" => $val["FILE"]["size"]))) {
                     $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_QUOTE_ERROR") . "\n";
                 }
             }
         }
     }
     return $arErrors;
 }
Exemple #22
0
 public function executeComponent()
 {
     if (!CModule::IncludeModule('webdav')) {
         return false;
     }
     $isVisual = isset($this->arParams['VISUAL']) ? (bool) $this->arParams['VISUAL'] : true;
     $pathToAjax = isset($this->arParams['AJAX_PATH']) ? $this->arParams['AJAX_PATH'] : '/bitrix/components/bitrix/webdav.disk/ajax.php';
     try {
         if ($isVisual) {
             $diskEnabled = \Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk');
             $quota = CDiskQuota::GetDiskQuota();
             $this->arResult['showDiskQuota'] = false;
             //$quota !== true; //now without quota
             $this->arResult['diskSpace'] = (double) COption::GetOptionInt('main', 'disk_space') * 1024 * 1024;
             $this->arResult['quota'] = $quota;
             $this->arResult['ajaxIndex'] = $pathToAjax;
             $this->arResult['ajaxStorageIndex'] = '/desktop_app/storage.php';
             if ($diskEnabled) {
                 $this->arResult['isInstalledDisk'] = \Bitrix\Disk\Desktop::isDesktopDiskInstall();
                 $this->arResult['personalLibIndex'] = '/company/personal/user/' . $this->getUser()->getId() . '/disk/path/';
             } else {
                 $this->arResult['isInstalledDisk'] = (bool) CWebDavTools::isDesktopDiskInstall();
                 $this->arResult['personalLibIndex'] = '/company/personal/user/' . $this->getUser()->getId() . '/files/lib/';
             }
             $this->arResult['isInstalledPull'] = (bool) IsModuleInstalled('pull');
             $this->arResult['currentUser'] = array('id' => $this->getUser()->getId(), 'formattedName' => $this->getUser()->getFormattedName());
             $this->getApplication()->addHeadScript('/bitrix/components/bitrix/webdav.disk/disk.js');
             $this->includeComponentTemplate();
             return;
         }
         CTimeZone::Disable();
         //decode from utf-8 to site LANG_CHARSET
         CUtil::decodeURIComponent($_POST);
         $this->checkUser()->runAction();
         CTimeZone::Enable();
     } catch (CWebDavBadStorageAfterMigrateException $e) {
         CTimeZone::Enable();
         $this->sendJsonResponse(array('status' => CWebDavDiskDispatcher::STATUS_ERROR, 'message' => 'Could not get Disk\\Storage. Perhaps, it is old client, which does not reconnect. '), 500);
     } catch (CWebDavSymlinkMoveFakeErrorException $e) {
         CTimeZone::Enable();
         $this->sendJsonResponse(array('status' => CWebDavDiskDispatcher::STATUS_ERROR, 'message' => 'This is not really error. Move symlink folders.'));
     } catch (CWebDavAccessDeniedException $e) {
         CTimeZone::Enable();
         $this->sendJsonResponse(array('status' => CWebDavDiskDispatcher::STATUS_ACCESS_DENIED, 'message' => $e->getMessage()));
     } catch (Exception $e) {
         CTimeZone::Enable();
         $response = array('status' => 'error', 'message' => $e->getMessage());
         if ($this->dispatcher) {
             $errors = $this->dispatcher->getErrors();
             if ($errors) {
                 $response['detail'] = $errors;
             }
         }
         $this->sendJsonResponse($response);
     }
     return;
 }
Exemple #23
0
	public static function InsertMainItems()
	{
		if(defined('BX_PUBLIC_MODE') && BX_PUBLIC_MODE == 1)
			return false;

		global $USER;

		if(!$USER->IsAuthorized())
			return false;

		//Updates
		if($USER->IsAdmin() || $USER->CanDoOperation('install_updates'))
		{
			$update_res = UpdateTools::GetUpdateResult();

			$updAIParams = array(
				"TITLE" => GetMessage("top_panel_ai_updates"),
				"COLOR" => 'gray',
				"SORT" => 12
			);

			//update_autocheck == true and we have something to show
			if ($update_res['result'] === true && $update_res['tooltip'])
			{
				$updAIParams["HTML"] = $update_res['tooltip'];
				$updAIParams["FOOTER"] = '<a href="/bitrix/admin/update_system.php?lang='.LANGUAGE_ID.'">'.GetMessage("top_panel_ai_upd_instl").'</a>';
				$updAIParams["ALERT"] = true;
			}
			else if ($update_res['error'] <> '') // update error
			{
				$updAIParams["TITLE"] .= " - ".GetMessage("top_panel_ai_title_err");
				$updAIParams["HTML"] = trim(self::CutErrorId($update_res['error']));
				$updAIParams["FOOTER"] = '<a href="/bitrix/admin/update_system.php?refresh=Y&lang='.LANGUAGE_ID.'">'.GetMessage("top_panel_ai_upd_chk").'</a>';
				$updAIParams["ALERT"] = true;
			}
			else // update_autocheck == false
			{
				//last update date time
				$updateDate = COption::GetOptionString("main", "update_system_update", false);
				// remove seconds
				$updateDate = $updateDate ? CDatabase::FormatDate($updateDate, "DD.MM.YYYY HH:MI:SS", "DD.MM.YYYY HH:MI") : false;

				$updAIParams["HTML"] = '<span class="adm-informer-strong-text">'.GetMessage("top_panel_ai_sys_ver").' '.SM_VERSION."</span><br>";
				$updAIParams["HTML"] .= $updateDate ? GetMessage("top_panel_ai_upd_last").'<br>'.$updateDate : GetMessage("top_panel_ai_upd_never");
				$updAIParams["FOOTER"] = '<a href="/bitrix/admin/update_system.php?refresh=Y&lang='.LANGUAGE_ID.'">'.GetMessage("top_panel_ai_upd_chk").'</a>';
				$updAIParams["ALERT"] = false;
			}

			self::AddItem($updAIParams);
		}

		//Disk space (quota)
		$maxQuota = COption::GetOptionInt("main", "disk_space", 0)*1048576;
		if ($maxQuota > 0)
		{
			$quota = new CDiskQuota();
			$free = $quota->GetDiskQuota();
			$freeMB = CFile::FormatSize($free,1);
			$free = round($free/($maxQuota)*100);

			$qAIParams = array(
				"TITLE" => GetMessage("top_panel_ai_used_space"),
				"COLOR" => "green",
				"ALERT" => ($free < 10 ? true : false)
				);

			$qAIParams["HTML"] = '
	<div class="adm-informer-item-section">
		<span class="adm-informer-item-l"><span class="adm-informer-strong-text">'.GetMessage("top_panel_ai_in_all").'</span> '.CFile::FormatSize($maxQuota,1).'</span>
		<span class="adm-informer-item-r"><span class="adm-informer-strong-text">'.GetMessage("top_panel_ai_in_aviable").'</span> '.$freeMB.'</span>
	</div>
	<div class="adm-informer-status-bar-block" >
		<div class="adm-informer-status-bar-indicator" style="width:'.(100-$free).'%; "></div>
		<div class="adm-informer-status-bar-text">'.(100-$free).'%</div>
	</div>
	<div class="adm-informer-item-section"><span class="adm-informer-strong-text">'.GetMessage("top_panel_ai_in_recomend").'</span> '.GetMessage("top_panel_ai_in_no").'</div>';

			self::AddItem($qAIParams);
		}

		if($USER->IsAdmin() && in_array(LANGUAGE_ID, array("ru", "ua")))
		{
			$cModules = COption::GetOptionString("main", "mp_modules_date", "");
			$arModules = array();
			if(strlen($cModules) > 0)
				$arModules = unserialize($cModules);

			$mCnt = count($arModules);
			if($mCnt > 0)
			{
				foreach($arModules as $id => $module)
				{
					if(isModuleInstalled($module["ID"]))
					{
						if($module["TMS"]+3600*24*14 < time())
						{
							$script = "
							<script type=\"text/javascript\">
							function hideMpAnswer(el, module)
							{
								if(el.parentNode.parentNode.parentNode)
									BX.hide(el.parentNode.parentNode.parentNode);
									BX.ajax({
										'method': 'POST',
										'dataType': 'html',
										'url': '/bitrix/admin/partner_modules.php',
										'data': 'module='+module+'&".bitrix_sessid_get()."&act=unnotify',
										'async': true,
										'processData': false

									});
							}
							</script>";
							
							$arParams = array(
									'TITLE' => GetMessage("top_panel_ai_marketplace"),
									'COLOR' => 'green',
									'FOOTER' => "<a href=\"javascript:void(0)\" onclick=\"hideMpAnswer(this, '".CUtil::JSEscape($module["ID"])."')\" style=\"float: right !important; font-size: 0.8em !important;\">".GetMessage("top_panel_ai_marketplace_hide")."</a><a href=\"http://marketplace.1c-bitrix.".LANGUAGE_ID."/solutions/#ID#/#comments\" target=\"_blank\" onclick=\"hideMpAnswer(this, '".CUtil::JSEscape($module["ID"])."')\">".GetMessage("top_panel_ai_marketplace_add")."</a>",
									GetMessage("top_panel_ai_marketplace_link", array("#ID#" => $module["ID"], "#ADIT#" => "")),
									'ALERT' => true,
									'HTML' => GetMessage("top_panel_ai_marketplace_descr", array("#NAME#" => $module["NAME"], "#ID#" => $module["ID"])).$script,
								);
							self::AddItem($arParams);
						}
					}
					else
						unset($arModules[$id]);
				}
				if($mCnt != count($arModules))
				{
					COption::SetOptionString("main", "mp_modules_date", serialize($arModules));
				}
			}

		}

		foreach(GetModuleEvents("main", "OnAdminInformerInsertItems", true) as $arHandler)
			ExecuteModuleEventEx($arHandler);

		return count(self::$items);
	}
Exemple #24
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php";
if (!$USER->CanDoOperation('edit_other_settings')) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$res = false;
if (isset($_REQUEST["id"]) && strLen(trim($_REQUEST["id"])) > 0 && check_bitrix_sessid()) {
    $quota = new CDiskQuota();
    $_REQUEST["recount"] = $_REQUEST["recount"] == "begin" ? true : false;
    if (strToLower($_REQUEST["id"]) == "db") {
        $_SESSION["SESS_RECOUNT_DB"] = "Y";
        $res = $quota->SetDBSize();
    } else {
        $res = $quota->Recount($_REQUEST["id"], $_REQUEST["recount"]);
    }
}
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_popup_admin.php";
if ($res !== false) {
    ?>
<script type="text/javascript">
	if (!window.parent.window.result)
		window.parent.window.result = new Array();
	window.parent.window.result['done'] = true;
<?php 
    if ($res["status"] == "error") {
        ?>
	window.parent.window.result['stop'] = true;
	window.parent.window.result['error'] = true;
<?php 
    } else {
Exemple #25
0
 function SaveFileContent($abs_path, $strContent)
 {
     $strContent = str_replace("\r\n", "\n", $strContent);
     $file = array();
     $this->ResetException();
     foreach (GetModuleEvents("main", "OnBeforeChangeFile", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($abs_path, &$strContent)) == false) {
             if (!$this->GetException()) {
                 $this->ThrowException(GetMessage("main_save_file_handler_error", array("#HANDLER#" => $arEvent["TO_NAME"])));
             }
             return false;
         }
     }
     $io = CBXVirtualIo::GetInstance();
     $fileIo = $io->GetFile($abs_path);
     $io->CreateDirectory($fileIo->GetPath());
     if ($fileIo->IsExists()) {
         $file["exists"] = true;
         if (!$fileIo->IsWritable()) {
             $fileIo->MarkWritable();
         }
         $file["size"] = $fileIo->GetFileSize();
     }
     /****************************** QUOTA ******************************/
     if (COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (false === $quota->checkDiskQuota(array("FILE_SIZE" => intVal(strLen($strContent) - intVal($file["size"]))))) {
             $this->ThrowException($quota->LAST_ERROR, "BAD_QUOTA");
             return false;
         }
     }
     /****************************** QUOTA ******************************/
     if ($fileIo->PutContents($strContent)) {
         $fileIo->MarkWritable();
     } else {
         if ($file["exists"]) {
             $this->ThrowException(GetMessage("MAIN_FILE_NOT_CREATE"), "FILE_NOT_CREATE");
         } else {
             $this->ThrowException(GetMessage("MAIN_FILE_NOT_OPENED"), "FILE_NOT_OPEN");
         }
         return false;
     }
     bx_accelerator_reset();
     $site = CSite::GetSiteByFullPath($abs_path);
     $DOC_ROOT = CSite::GetSiteDocRoot($site);
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         //Fix for name case under Windows
         $abs_path = strtolower($abs_path);
         $DOC_ROOT = strtolower($DOC_ROOT);
     }
     if (strpos($abs_path, $DOC_ROOT) === 0 && $site !== false) {
         $DOC_ROOT = rtrim($DOC_ROOT, "/\\");
         $path = "/" . ltrim(substr($abs_path, strlen($DOC_ROOT)), "/\\");
         foreach (GetModuleEvents("main", "OnChangeFile", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($path, $site));
         }
     }
     /****************************** QUOTA ******************************/
     if (COption::GetOptionInt("main", "disk_space") > 0) {
         $fs = $fileIo->GetFileSize();
         CDiskQuota::updateDiskQuota("files", intVal($fs - intVal($file["size"])), "update");
     }
     /****************************** QUOTA ******************************/
     return true;
 }
 } elseif ($arFile["error"] == 1 || $arFile["error"] == 2) {
     $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_SIZE_ERROR", array('#FILE_NAME#' => $pathto)) . "\n";
 } elseif (($mess = CFileMan::CheckFileName(str_replace('/', '', $pathto))) !== true) {
     $strWarning .= $mess . ".\n";
 } else {
     if ($io->FileExists($DOC_ROOT . $pathto)) {
         $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_FILE_EXISTS1") . " \"" . $pathto . "\" " . GetMessage("FILEMAN_FILEUPLOAD_FILE_EXISTS2") . ".\n";
     } elseif (!$USER->IsAdmin() && (HasScriptExtension($pathto) || substr(CFileman::GetFileName($pathto), 0, 1) == ".")) {
         $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_PHPERROR") . " \"" . $pathto . "\".\n";
     } else {
         $bQuota = true;
         if (COption::GetOptionInt("main", "disk_space") > 0) {
             $f = $io->GetFile($arFile["tmp_name"]);
             $bQuota = false;
             $size = $f->GetFileSize();
             $quota = new CDiskQuota();
             if ($quota->checkDiskQuota(array("FILE_SIZE" => $size))) {
                 $bQuota = true;
             }
         }
         if ($bQuota) {
             if (!$io->Copy($arFile["tmp_name"], $DOC_ROOT . $pathto)) {
                 $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_FILE_CREATE_ERROR") . " \"" . $pathto . "\"\n";
             } elseif (COption::GetOptionInt("main", "disk_space") > 0) {
                 CDiskQuota::updateDiskQuota("file", $size, "copy");
             }
             $f = $io->GetFile($DOC_ROOT . $pathto);
             $f->MarkWritable();
             $module_id = 'fileman';
             if (COption::GetOptionString($module_id, "log_page", "Y") == "Y") {
                 $res_log['path'] = substr($pathto, 1);