Exemplo n.º 1
0
 private static function GetSocNetEvent()
 {
     if (!(IsModuleInstalled('webdav') && CModule::IncludeModule('webdav'))) {
         return null;
     }
     if (!self::$SOC_NET_EVENT) {
         self::$SOC_NET_EVENT = CWebDavSocNetEvent::GetRuntime();
     }
     return self::$SOC_NET_EVENT;
 }
Exemplo n.º 2
0
 public static function GetRuntime()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
         if (!CModule::IncludeModule('webdav') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('socialnetwork')) {
             return false;
         }
     }
     return self::$instance;
 }
Exemplo n.º 3
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("webdav")) {
    //ShowError(GetMessage("SONET_WD_MODULE_IS_NOT_INSTALLED"));
    return 0;
} elseif (!CModule::IncludeModule("iblock")) {
    //ShowError(GetMessage("SONET_IB_MODULE_IS_NOT_INSTALLED"));
    return 0;
}
$file = trim(preg_replace("'[\\\\/]+'", "/", dirname(__FILE__) . "/../lang/" . LANGUAGE_ID . "/include/webdav_2.php"));
__IncludeLang($file);
$obDavEventHandler = CWebDavSocNetEvent::GetRuntime();
$obDavEventHandler->SetSocnetVars($arResult, $arParams);
AddEventHandler("socialnetwork", "OnBeforeSocNetGroupUpdate", array($obDavEventHandler, "SocNetGroupRename"));
Exemplo n.º 4
0
 function CWebDavIblock($IBLOCK_ID, $base_url, $arParams = array())
 {
     $arParams = is_array($arParams) ? $arParams : array();
     $this->_originalParams = $arParams;
     $this->_symlinkMode = !empty($arParams['symlinkMode']);
     $this->_symlinkSectionData = empty($arParams['symlinkSectionData']) ? array() : $arParams['symlinkSectionData'];
     $this->_symlinkRealRootSectionData = empty($arParams['symlinkRealRootSectionData']) ? array() : $arParams['symlinkRealRootSectionData'];
     $this->IBLOCK_ID = $IBLOCK_ID;
     $this->IBLOCK_TYPE = $arParams["IBLOCK_TYPE"];
     $this->FORUM_ID = isset($arParams['FORUM_ID']) && intval($arParams['FORUM_ID']) > 0 ? intval($arParams['FORUM_ID']) : null;
     $this->cachePathBase = str_replace(array("///", "//"), "/", "/" . SITE_ID . "/webdav/" . $this->IBLOCK_ID . "/");
     $this->CACHE_PATH = $this->cachePathBase;
     $this->CACHE_TIME = array_key_exists("CACHE_TIME", $arParams) ? $arParams["CACHE_TIME"] : 0;
     $this->cacheType = array_key_exists("CACHE_TYPE", $arParams) ? $arParams["CACHE_TYPE"] : "N";
     if ($this->cacheType == "Y" || $this->cacheType == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "Y") {
         $this->CACHE_TIME = intval($arParams["CACHE_TIME"]);
     } else {
         $this->CACHE_TIME = 0;
     }
     $arParams["CACHE_TIME"] = $this->CACHE_TIME;
     if ($this->CACHE_TIME > 0) {
         $this->CACHE_OBJ = new CPHPCache();
     }
     if (!$this->SetRootSection($arParams["ROOT_SECTION_ID"], false, empty($arParams['PLEASE_DO_NOT_MAKE_REDIRECT']))) {
         $this->arError[] = array("id" => "root_section_is_not_found", "text" => GetMessage("WD_ROOT_SECTION_NOT_FOUND"));
     } else {
         if (self::$first_run) {
             AddEventHandler("iblock", "OnAfterIBlockSectionAdd", array($this, "UpdateRootSection"));
         }
     }
     if (COption::GetOptionString('webdav', 'webdav_socnet', 'Y') === 'Y' && self::$first_run && CModule::IncludeModule("socialnetwork")) {
         $obDavEventHandler = CWebDavSocNetEvent::GetRuntime();
         $obDavEventHandler->object = $this;
         AddEventHandler("webdav", "OnFileAdd", array($obDavEventHandler, "SocnetLogFileAdd"));
         AddEventHandler("webdav", "OnFileAdd", array($obDavEventHandler, "SocnetNotify"));
         AddEventHandler("webdav", "OnFileUpdate", array($obDavEventHandler, "SocnetLogFileUpdate"));
         AddEventHandler("webdav", "OnFileMoveFinished", array($obDavEventHandler, "SocnetLogFileMove"));
         AddEventHandler("webdav", "OnFileTrash", array($obDavEventHandler, "SocnetLogFileDelete"));
         AddEventHandler("webdav", "OnFileDelete", array($obDavEventHandler, "SocnetLogFileDelete"));
         if (CModule::IncludeModule('forum')) {
             AddEventHandler("forum", "onAfterMessageAdd", array($obDavEventHandler, "SocnetLogMessageAdd"));
             AddEventHandler("forum", "onAfterMessageDelete", array($obDavEventHandler, "SocnetLogMessageDelete"));
             AddEventHandler("forum", "onAfterMessageUpdate", array($obDavEventHandler, "SocnetLogMessageUpdate"));
         }
     }
     $this->CWebDavBase($base_url);
     if (!IsModuleInstalled("iblock")) {
         $this->arError[] = array("id" => "module iblock is not installed. ", "text" => GetMessage("W_IBLOCK_IS_NOT_INSTALLED"));
         return false;
     }
     $this->e_rights = CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E";
     if ($this->e_rights) {
         $this->permission_real = 'X';
     } else {
         $this->permission_real = $this->GetPermission('IBLOCK', $this->IBLOCK_ID);
     }
     $this->permission = empty($arParams["PERMISSION"]) ? $this->permission_real : $arParams["PERMISSION"];
     if ($GLOBALS['USER']->CanDoOperation('webdav_change_settings')) {
         $this->permission = $this->permission_real = 'X';
     }
     $this->check_creator = false;
     if ($this->permission_real < "W" && $this->permission > $this->permission_real) {
         $this->check_creator = $arParams["CHECK_CREATOR"] == "Y" ? true : false;
     }
     $this->USER["GROUPS"] = $GLOBALS["USER"]->GetUserGroupArray();
     $this->workflow = false;
     if (CIBlock::GetArrayByID($IBLOCK_ID, "WORKFLOW") != "N" && IsModuleInstalled("workflow")) {
         CModule::IncludeModule("workflow");
         $this->workflow = 'workflow';
         $this->permission_wf_edit = true;
         if ($this->permission == "U" && !CWorkflow::IsAdmin()) {
             $this->permission_wf_edit = false;
             $db_res = CWorkflowStatus::GetDropDownList("Y", "desc");
             if ($db_res && ($res = $db_res->Fetch())) {
                 do {
                     if (CIBlockElement::WF_GetStatusPermission($res["REFERENCE_ID"]) >= 2) {
                         $this->permission_wf_edit = true;
                         break;
                     }
                 } while ($res = $db_res->Fetch());
             }
         }
     } elseif (IsModuleInstalled("bizproc")) {
         CModule::IncludeModule("bizproc");
         $this->workflow = CIBlock::GetArrayByID($IBLOCK_ID, "BIZPROC") != "N" ? 'bizproc' : 'bizproc_limited';
         $this->wfParams['AUTO_PUBLISH'] = "N";
         if (isset($arParams['AUTO_PUBLISH'])) {
             $this->wfParams['AUTO_PUBLISH'] = $arParams['AUTO_PUBLISH'] == "Y" ? "Y" : "N";
         }
         if (isset($arParams['FILES_AUTO_PUBLISH'])) {
             $this->wfParams['AUTO_PUBLISH'] = $arParams['FILES_AUTO_PUBLISH'] == "Y" ? "Y" : "N";
         }
         $this->wfParams['DOCUMENT_TYPE'] = array("webdav", "CIBlockDocumentWebdav", "iblock_" . $IBLOCK_ID);
         if (is_array($arParams["DOCUMENT_TYPE"])) {
             $this->wfParams['DOCUMENT_TYPE'][1] = $arParams["DOCUMENT_TYPE"][1];
             $this->wfParams['DOCUMENT_TYPE'][2] = $arParams["DOCUMENT_TYPE"][2];
         }
         if (self::$first_run) {
             AddEventHandler('bizproc', 'OnBeforeDeleteFileFromHistory', array('CWebdavDocumentHistory', 'OnBeforeDeleteFileFromHistory'));
         }
         if ($this->wfParams['DOCUMENT_TYPE'][1] == "CIBlockDocumentWebdavSocnet") {
             if ($this->workflow == 'bizproc') {
                 $tmp = explode("_", $this->wfParams['DOCUMENT_TYPE'][2]);
                 if (intval($tmp[3]) > 0) {
                     $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "SOCNET_GROUP_ID" => false, "SECTION_ID" => 0);
                     if ($tmp[2] == "user") {
                         $arFilter["CREATED_BY"] = $tmp[3];
                         //we don't use BP in user lib;
                         $this->workflow = 'bizproc_limited';
                     } else {
                         $arFilter["SOCNET_GROUP_ID"] = $tmp[3];
                         $db_res = CIBlockSection::GetList(array(), $arFilter, false, array("ID", "UF_USE_BP"));
                         if ($db_res && ($res = $db_res->Fetch())) {
                             $this->workflow = $res["UF_USE_BP"] == "N" ? 'bizproc_limited' : 'bizproc';
                         }
                     }
                 }
             }
             if (method_exists($this->wfParams['DOCUMENT_TYPE'][1], "GetUserGroups")) {
                 $this->USER["GROUPS"] = call_user_func_array(array($this->wfParams['DOCUMENT_TYPE'][1], "GetUserGroups"), array($this->wfParams['DOCUMENT_TYPE'], null, $GLOBALS["USER"]->GetID()));
             }
         }
         if ($this->workflow == 'bizproc') {
             AddEventHandler('webdav', 'OnBizprocPublishDocument', array($this, 'OnBizprocPublishDocument'));
         }
     }
     $this->file_prop = strtoupper(isset($arParams["NAME_FILE_PROPERTY"]) ? $arParams["NAME_FILE_PROPERTY"] : "FILE");
     if ($this->permission == "U" && $this->workflow != "workflow" && $this->workflow != "bizproc") {
         $this->permission = "R";
     }
     if ($arParams["SHORT_PATH_TEMPLATE"]) {
         $this->short_path_template = $arParams["SHORT_PATH_TEMPLATE"];
     }
     if ($arParams["ATTRIBUTES"]) {
         $this->attributes = $arParams["ATTRIBUTES"];
     }
     $this->_check_iblock_prop(array("WEBDAV_INFO" => array("name" => GetMessage("WD_PROPERTY_WEBDAV_INFO"), "type" => "S"), "WEBDAV_SIZE" => array("name" => GetMessage("WD_PROPERTY_FILE_SIZE"), "type" => "N"), static::PROPERTY_VERSION => array("name" => GetMessage("WD_PROPERTY_VERSION"), "type" => "N"), $this->file_prop => array("name" => GetMessage("WD_PROPERTY_NAME_FILE"), "type" => "F", "properties" => array("SEARCHABLE" => "Y"))));
     $oIB = new CIBlock();
     $arIBlock = $oIB->GetArrayByID($this->IBLOCK_ID);
     if (!array_key_exists("NOT_SAVE_SUG_FILES", $arParams)) {
         if (strpos($arIBlock['CODE'], 'shared_files') !== false) {
             // without trailing slash redirects POST request to GET request
             if (strlen($this->base_url) > 0) {
                 $this->LibOptions('shared_files', false, SITE_ID, array('id' => $this->IBLOCK_ID, 'base_url' => $this->base_url . '/'));
             }
         } elseif (strpos($arIBlock['CODE'], 'group_files') !== false) {
             $this->LibOptions('group_files', false, SITE_ID, array('id' => $this->IBLOCK_ID));
         } elseif (strpos($arIBlock['CODE'], 'user_files') !== false) {
             $this->LibOptions('user_files', false, SITE_ID, array('id' => $this->IBLOCK_ID));
         }
     }
     if ($arIBlock['INDEX_SECTION'] == 'Y' && strlen(trim($arIBlock['SECTION_PAGE_URL'])) == 0) {
         $arIBlock['SECTION_PAGE_URL'] = str_replace(array("///", "//"), "/", $arIBlock['LIST_PAGE_URL'] . "/folder/view/#SECTION_ID#/");
         $oIB->Update($this->IBLOCK_ID, $arIBlock);
     }
     $this->GetUfEntity();
     self::$first_run = false;
 }
Exemplo n.º 5
0
 protected function saveNewFile(array $fileData)
 {
     $filename = CTempFile::GetFileName(uniqid('_wd'));
     CheckDirPath($filename);
     $doc = $this->getDocHandler()->downloadFile(array('id' => $this->getFileId(), 'mimeType' => $this->getWebdav()->get_mime_type('1.' . $fileData['createType'])));
     file_put_contents($filename, $doc['content']);
     global $USER;
     $dataUserSection = CWebDavIblock::getRootSectionDataForUser($USER->GetID());
     if (!$dataUserSection) {
         return array('status' => 'error');
     }
     $createdDocFolderId = CIBlockWebdavSocnet::createCreatedDocFolder($dataUserSection['IBLOCK_ID'], $dataUserSection['SECTION_ID'], $USER->GetID());
     if (!$createdDocFolderId) {
         return array('status' => 'error');
     }
     $storage = new CWebDavStorageCore();
     $storage->setStorageId(array('IBLOCK_ID' => $dataUserSection['IBLOCK_ID'], 'IBLOCK_SECTION_ID' => $dataUserSection['SECTION_ID']));
     $nameToSavedFile = $storage->regenerateNameIfNonUnique($doc['name'], $createdDocFolderId);
     $tmpFile = new CWebDavStubTmpFile();
     $tmpFile->path = $filename;
     try {
         $fileData = $storage->addFile($nameToSavedFile, $createdDocFolderId, $tmpFile);
         $response = array('status' => 'success', 'elementId' => $fileData['extra']['id'], 'sectionId' => $fileData['extra']['sectionId'], 'name' => $nameToSavedFile, 'sizeInt' => $fileData['size'], 'type' => CWebDavBase::get_mime_type($nameToSavedFile), 'link' => str_replace('#element_id#', $fileData['extra']['id'], CWebDavSocNetEvent::getRuntime()->arPath['ELEMENT_EDIT_INLINE_URL']), 'nameWithoutExtension' => GetFileNameWithoutExtension($nameToSavedFile));
     } catch (Exception $e) {
         $response = array('status' => 'error');
     }
     return $response;
 }