• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/editdoccomponentbase.php
  • Класс: CWebDavEditDocComponentBase
  • Вызов: CWebDavEditDocComponentBase::executeComponent
public function executeComponent()
{
	try
	{
		CUtil::JSPostUnescape();
		$this->checkSessid();
		if(!CModule::IncludeModule('socialservices'))
		{
			$this->sendJsonResponse(array('error' => GetMessage('WD_DOC_INSTALL_SOCSERV')));
		}

		if(empty($_GET['proccess']))
		{
			$this->includeComponentTemplate('startpage');
			return;
		}

		$this->setFileId($_REQUEST['id']);
		$this->setVersionId($_REQUEST['v']);
		$this->setAction(empty($_REQUEST['action'])? '' : $_REQUEST['action']);

		if($this->isPublicNewFile())
		{
		}
		elseif($this->isSaveNewFile())
		{
		}
		else
		{
			$wdElement = array();
			if(!empty($_REQUEST['elementId']))
			{
				$wdElement = array('elementId' => (int)$_REQUEST['elementId']);
			}
			$this->checkPermission($wdElement);
			$lockInfo = $this->checkLock();

			if($lockInfo)
			{
				$this->sendJsonResponse(array('error' => GetMessage('WD_DOC_ATTEMPT_EDIT_LOCK_DOCUMENT')));
			}
		}

		$this->checkActiveSocServ();
		$oAuthUrl = CUtil::JSEscape($this->getOAuthUrlBySocServ());
		$accessToken = $this->getAccessTokenBySocServ();
		$this
			->setAccessToken($accessToken)
		;
		$this
			->initDocHandler()
		;
		$this
			->getDocHandler()
				->setAccessToken($this->getAccessToken())
		;

		if(empty($accessToken))
		{
			$this->sendJsonResponse(array(
				'authUrl' => $oAuthUrl,
			));
		}
		else
		{
			//todo hack. SocServ set backurl!
			if(mb_strpos($_SERVER['HTTP_REFERER'], 'tools/oauth'))
			{
				$curPath = CHTTP::urlDeleteParams($_SERVER['REQUEST_URI'], array("proccess", "sessid",));
				$curPath = CHTTP::urlAddParams($curPath, array('sessid' => bitrix_sessid()));
				//restart
				LocalRedirect($curPath);
			}

			if($this->isPublicNewFile())
			{
				$response = $this->publicBlankFile(new CWebDavBlankDocument($this->arParams['createType']));
				//todo bad hack. bad hack
				if($this->getDocHandler()->isRequiredAuthorization())
				{
					$this->sendJsonResponse(array(
						'authUrl' => $oAuthUrl,
					));
				}
				$this->sendJsonResponse($response);
			}
			elseif($this->isSaveNewFile())
			{
				$response = $this->saveNewFile(array(
					'isDropped' => true,
					'createType' => $this->arParams['createType'],
//						'iblockId' => '',
//						'sectionId' => '',
				));
				$this->removeFile();
				$this->sendJsonResponse($response);
			}
			elseif($this->isRenameFile())
			{
				$response = $this->renameFile(array(
					'newName' => $_REQUEST['newName'],
					'elementId' => (int)$_REQUEST['elementId'],
					'sectionId' => (int)$_REQUEST['sectionId'],
				));
				$this->sendJsonResponse($response);
			}
			elseif(!empty($_REQUEST['commit']) && $this->getFileId())
			{
				$deletedSession = $this->deleteSession(true);
				$response = $this->commitFile();
				if(is_array($deletedSession) && $this->isLastSession())
				{
					$this->removeFile($deletedSession);
				}

				$this->sendJsonResponse($response);
			}
			elseif(!empty($_REQUEST['discard']) && $this->getFileId())
			{
				$deletedSession = $this->deleteSession(true);
				if(is_array($deletedSession) && $this->isLastSession())
				{
					$this->removeFile($deletedSession);
					$this->sendJsonResponse(array('status' => 'success'));
				}
				$this->sendJsonResponse(array('status' => 'error'));
			}
			else //publicDoc
			{
				$response = $this->publicFile();
				//todo bad hack. bad hack
				if($this->getDocHandler()->isRequiredAuthorization())
				{
					$this->sendJsonResponse(array(
						'authUrl' => $oAuthUrl,
					));
				}
				$this->sendJsonResponse($response);
			}
		}

		return;
	}
	catch(Exception $e)
	{
		//$this->sendJsonResponse(array('error' => $e->getMessage()));
	}

	return;
}