Пример #1
0
 /**
  * Gets data attributes by object (folder or file) to viewer.
  * @param File|Folder|BaseObject $object Target object.
  * @param array                  $additionalParams Additional parameters 'relativePath', 'externalId', 'canUpdate', 'showStorage'.
  * @return string
  */
 public static function getAttributesByObject(BaseObject $object, array $additionalParams = array())
 {
     $urlManager = Driver::getInstance()->getUrlManager();
     $name = $object->getName();
     $dateTime = $object->getUpdateTime();
     if ($object instanceof Folder) {
         $user = $object->getCreateUser();
         $dataAttributesForViewer = 'data-bx-viewer="folder" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="" ' . 'data-bx-owner="' . htmlspecialcharsbx($user ? $user->getFormattedName() : '') . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
         return $dataAttributesForViewer;
     }
     if (!$object instanceof File) {
         return '';
     }
     if (DocumentHandler::isEditable($object->getExtension())) {
         $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowFileByService($object->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="' . (DocumentHandler::isNeedConvertExtension($object->getExtension()) ? '1' : '') . '" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($object->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     } elseif (Viewer::isViewable($object->getExtension())) {
         $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowFileByService($object->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="0" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($object->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     } elseif (TypeFile::isImage($object)) {
         $dataAttributesForViewer = 'data-bx-viewer="image" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     } else {
         $user = $object->getCreateUser();
         $dataAttributesForViewer = 'data-bx-viewer="unknown" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-owner="' . htmlspecialcharsbx($user ? $user->getFormattedName() : '') . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($object->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     }
     $dataAttributesForViewer .= " bx-attach-file-id=\"{$object->getId()}\"" . " data-bx-version=\"\"" . " data-bx-history=\"\"" . " data-bx-historyPage=\"\"";
     if (!empty($additionalParams['relativePath'])) {
         $dataAttributesForViewer .= ' data-bx-relativePath="' . htmlspecialcharsbx($additionalParams['relativePath'] . '/' . $name) . '" ';
     }
     if (!empty($additionalParams['externalId'])) {
         $dataAttributesForViewer .= ' data-bx-externalId="' . htmlspecialcharsbx($additionalParams['externalId']) . '" ';
     }
     if (!empty($additionalParams['canUpdate'])) {
         $dataAttributesForViewer .= ' data-bx-edit="' . $urlManager->getUrlForStartEditFile($object->getId(), 'gdrive') . '" ';
     }
     if (!empty($additionalParams['showStorage'])) {
         $dataAttributesForViewer .= ' data-bx-storage="' . htmlspecialcharsbx($object->getParent()->getName()) . '" ';
     }
     return $dataAttributesForViewer;
 }
Пример #2
0
 /**
  * @param $path
  * @param File|Folder|Object $object
  * @return CDavResource
  */
 protected function getResourceByObject($path, BaseObject $object)
 {
     $isFolder = $object instanceof Folder;
     $resource = new CDavResource($path . ($isFolder && substr($path, -1, 1) != "/" ? "/" : ""));
     $resource->AddProperty('name', $object->getName());
     if ($object instanceof File) {
         $resource->AddProperty('getcontentlength', $object->getSize());
     }
     $resource->AddProperty('creationdate', $object->getCreateTime()->getTimestamp());
     $resource->AddProperty('getlastmodified', $object->getUpdateTime()->getTimestamp());
     $resource->AddProperty('iscollection', $isFolder ? '1' : '0');
     if ($isFolder) {
         $resource->AddProperty('resourcetype', array('collection', ''));
         $resource->AddProperty('getcontenttype', 'httpd/unix-directory');
     } else {
         $resource->AddProperty('getcontenttype', '');
         $resource->AddProperty('isreadonly', '');
         $resource->AddProperty('ishidden', '');
         $resource->AddProperty('resourcetype', '');
     }
     $resource->AddProperty("supportedlock", "<D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry>");
     return $resource;
 }
Пример #3
0
 /**
  * @param $path
  * @param File|Folder|Object $object
  * @return CDavResource
  */
 protected function getResourceByObject($path, BaseObject $object)
 {
     $isFolder = $object instanceof Folder;
     $resource = new CDavResource($path . ($isFolder && substr($path, -1, 1) != "/" ? "/" : ""));
     $resource->AddProperty('name', $object->getName());
     if ($object instanceof File) {
         $resource->AddProperty('getcontentlength', $object->getSize());
     }
     $resource->AddProperty('creationdate', $object->getCreateTime()->getTimestamp());
     $resource->AddProperty('getlastmodified', $object->getUpdateTime()->getTimestamp());
     $resource->AddProperty('iscollection', $isFolder ? '1' : '0');
     $resource->AddProperty('Win32CreationTime', $object->getCreateTime()->getTimestamp(), "urn:schemas-microsoft-com:");
     $resource->AddProperty('Win32LastModifiedTime', $object->getUpdateTime()->getTimestamp(), "urn:schemas-microsoft-com:");
     if ($isFolder) {
         $resource->AddProperty('resourcetype', array('collection', ''));
         $resource->AddProperty('getcontenttype', 'httpd/unix-directory');
     } else {
         $resource->AddProperty('getcontenttype', '');
         $resource->AddProperty('isreadonly', '');
         $resource->AddProperty('ishidden', '');
         $resource->AddProperty('resourcetype', '');
     }
     $resource->AddProperty("supportedlock", "<D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry>");
     /*
       <D:response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
      	<D:href>/docs/shared/%D0%97%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8</D:href>
      	 <D:propstat>
      	  <D:prop>
      	   <D:resourcetype><D:collection/></D:resourcetype>
      	   <D:getcontenttype>httpd/unix-directory</D:getcontenttype>
      	   <D:creationdate ns0:dt="dateTime.tz">2014-05-12T08:37:25Z</D:creationdate>
      	   <D:getlastmodified ns0:dt="dateTime.rfc1123">Mon, 12 May 2014 08:37:25 GMT</D:getlastmodified>
      	   <D:iscollection/>
      	   <D:supportedlock><D:lockentry>
      						<D:lockscope><D:exclusive/></D:lockscope>
      						<D:locktype><D:write/></D:locktype>
      					</D:lockentry>
      					<D:lockentry>
      						<D:lockscope><D:shared/></D:lockscope>
      						<D:locktype><D:write/></D:locktype>
      					</D:lockentry></D:supportedlock>
      	 </D:prop>
      	 <D:status>HTTP/1.1 200 OK</D:status>
      	</D:propstat>
       </D:response>
     
     
       <D:response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
      	<D:href>/docs/shared/%D0%90%D0%BD%D0%BA%D0%B5%D1%82%D0%B0.docx</D:href>
      	 <D:propstat>
      	  <D:prop>
      	   <D:creationdate ns0:dt="dateTime.tz">2014-05-12T08:26:30Z</D:creationdate>
      	   <D:getlastmodified ns0:dt="dateTime.rfc1123">Mon, 12 May 2014 08:26:31 GMT</D:getlastmodified>
      	   <D:creationdate ns0:dt="dateTime.tz">2014-05-12T08:26:30Z</D:creationdate>
      	   <D:getlastmodified ns0:dt="dateTime.rfc1123">Mon, 12 May 2014 08:26:31 GMT</D:getlastmodified>
      	   <D:getcontenttype/>
      	   <D:getcontentlength>86838</D:getcontentlength>
      	   <D:isreadonly>false</D:isreadonly>
      	   <D:ishidden>false</D:ishidden>
      	   <D:iscollection>0</D:iscollection>
      	   <D:resourcetype/>
      	   <D:supportedlock><D:lockentry>
      						<D:lockscope><D:exclusive/></D:lockscope>
      						<D:locktype><D:write/></D:locktype>
      					</D:lockentry>
      					<D:lockentry>
      						<D:lockscope><D:shared/></D:lockscope>
      						<D:locktype><D:write/></D:locktype>
      					</D:lockentry></D:supportedlock>
      	 </D:prop>
      	 <D:status>HTTP/1.1 200 OK</D:status>
      	</D:propstat>
       </D:response>
     */
     return $resource;
 }