public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "asset")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "asset")]); } Element\Editlock::lock($this->getParam("id"), "asset"); $asset = Asset::getById(intval($this->getParam("id"))); $asset = clone $asset; if (!$asset instanceof Asset) { $this->_helper->json(["success" => false, "message" => "asset doesn't exist"]); } $asset->setMetadata(Asset\Service::expandMetadataForEditmode($asset->getMetadata())); $asset->setProperties(Element\Service::minimizePropertiesForEditmode($asset->getProperties())); //$asset->getVersions(); $asset->getScheduledTasks(); $asset->idPath = Element\Service::getIdPath($asset); $asset->userPermissions = $asset->getUserPermissions(); $asset->setLocked($asset->isLocked()); $asset->setParent(null); if ($asset instanceof Asset\Text) { $asset->data = $asset->getData(); } if ($asset instanceof Asset\Image) { $imageInfo = []; if ($asset->getWidth() && $asset->getHeight()) { $imageInfo["dimensions"] = []; $imageInfo["dimensions"]["width"] = $asset->getWidth(); $imageInfo["dimensions"]["height"] = $asset->getHeight(); } $exifData = $asset->getEXIFData(); if (!empty($exifData)) { $imageInfo["exif"] = $exifData; } $iptcData = $asset->getIPTCData(); if (!empty($exifData)) { $imageInfo["iptc"] = $iptcData; } $imageInfo["exiftoolAvailable"] = (bool) \Pimcore\Tool\Console::getExecutable("exiftool"); $asset->imageInfo = $imageInfo; } $asset->setStream(null); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new Model\Tool\Admin\EventDataContainer(object2array($asset)); \Pimcore::getEventManager()->trigger("admin.asset.get.preSendData", $this, ["asset" => $asset, "returnValueContainer" => $returnValueContainer]); if ($asset->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(["success" => false, "message" => "missing_permission"]); }
public function getAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "object")) { $this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "object"))); } Element\Editlock::lock($this->getParam("id"), "object"); $object = Object::getById(intval($this->getParam("id"))); // set the latest available version for editmode $latestObject = $this->getLatestVersion($object); // we need to know if the latest version is published or not (a version), because of lazy loaded fields in $this->getDataForObject() $objectFromVersion = $latestObject === $object ? false : true; $object = $latestObject; if ($object->isAllowed("view")) { $objectData = array(); $objectData["idPath"] = Element\Service::getIdPath($object); $objectData["previewUrl"] = $object->getClass()->getPreviewUrl(); $objectData["general"] = array(); $allowedKeys = array("o_published", "o_key", "o_id", "o_modificationDate", "o_creationDate", "o_classId", "o_className", "o_locked", "o_type", "o_parentId", "o_userOwner", "o_userModification"); foreach (get_object_vars($object) as $key => $value) { if (strstr($key, "o_") && in_array($key, $allowedKeys)) { $objectData["general"][$key] = $value; } } $objectData["general"]["o_locked"] = $object->isLocked(); $this->getDataForObject($object, $objectFromVersion); $objectData["data"] = $this->objectData; $objectData["metaData"] = $this->metaData; $objectData["layout"] = $object->getClass()->getLayoutDefinitions(); $objectData["properties"] = Element\Service::minimizePropertiesForEditmode($object->getProperties()); $objectData["userPermissions"] = $object->getUserPermissions(); $objectData["versions"] = array_splice($object->getVersions(), 0, 1); $objectData["scheduledTasks"] = $object->getScheduledTasks(); $objectData["general"]["allowVariants"] = $object->getClass()->getAllowVariants(); $objectData["general"]["showVariants"] = $object->getClass()->getShowVariants(); $objectData["general"]["fullpath"] = $object->getFullPath(); if ($object->getElementAdminStyle()->getElementIcon()) { $objectData["general"]["icon"] = $object->getElementAdminStyle()->getElementIcon(); } if ($object->getElementAdminStyle()->getElementIconClass()) { $objectData["general"]["iconCls"] = $object->getElementAdminStyle()->getElementIconClass(); } if ($object instanceof Object\Concrete) { $objectData["lazyLoadedFields"] = $object->getLazyLoadedFields(); } $objectData["childdata"]["id"] = $object->getId(); $objectData["childdata"]["data"]["classes"] = $object->getDao()->getClasses(); $currentLayoutId = $this->getParam("layoutId", null); $validLayouts = Object\Service::getValidLayouts($object); //master layout has id 0 so we check for is_null() if (is_null($currentLayoutId) && !empty($validLayouts)) { foreach ($validLayouts as $checkDefaultLayout) { if ($checkDefaultLayout->getDefault()) { $currentLayoutId = $checkDefaultLayout->getId(); } } } if (!empty($validLayouts)) { $objectData["validLayouts"] = array(); foreach ($validLayouts as $validLayout) { $objectData["validLayouts"][] = array("id" => $validLayout->getId(), "name" => $validLayout->getName()); } $user = Tool\Admin::getCurrentUser(); if ($currentLayoutId == 0 && !$user->isAdmin()) { $first = reset($validLayouts); $currentLayoutId = $first->getId(); } if ($currentLayoutId > 0) { // check if user has sufficient rights if ($validLayouts && $validLayouts[$currentLayoutId]) { $customLayout = Object\ClassDefinition\CustomLayout::getById($currentLayoutId); $customLayoutDefinition = $customLayout->getLayoutDefinitions(); $objectData["layout"] = $customLayoutDefinition; } else { $currentLayoutId = 0; } } elseif ($currentLayoutId == -1 && $user->isAdmin()) { $layout = Object\Service::getSuperLayoutDefinition($object); $objectData["layout"] = $layout; } $objectData["currentLayoutId"] = $currentLayoutId; } $objectData = $this->filterLocalizedFields($object, $objectData); Object\Service::enrichLayoutDefinition($objectData["layout"], $object); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new Model\Tool\Admin\EventDataContainer($objectData); \Pimcore::getEventManager()->trigger("admin.object.get.preSendData", $this, ["object" => $object, "returnValueContainer" => $returnValueContainer]); $this->_helper->json($returnValueContainer->getData()); } else { \Logger::debug("prevented getting object id [ " . $object->getId() . " ] because of missing permissions"); $this->_helper->json(array("success" => false, "message" => "missing_permission")); } }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "asset")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "asset")]); } Element\Editlock::lock($this->getParam("id"), "asset"); $asset = Asset::getById(intval($this->getParam("id"))); $asset = clone $asset; if (!$asset instanceof Asset) { $this->_helper->json(["success" => false, "message" => "asset doesn't exist"]); } $asset->setMetadata(Asset\Service::expandMetadataForEditmode($asset->getMetadata())); $asset->setProperties(Element\Service::minimizePropertiesForEditmode($asset->getProperties())); //$asset->getVersions(); $asset->getScheduledTasks(); $asset->idPath = Element\Service::getIdPath($asset); $asset->userPermissions = $asset->getUserPermissions(); $asset->setLocked($asset->isLocked()); $asset->setParent(null); if ($asset instanceof Asset\Text) { $asset->data = $asset->getData(); } if ($asset instanceof Asset\Image) { $imageInfo = []; if ($asset->getWidth() && $asset->getHeight()) { $imageInfo["dimensions"] = []; $imageInfo["dimensions"]["width"] = $asset->getWidth(); $imageInfo["dimensions"]["height"] = $asset->getHeight(); } if (function_exists("exif_read_data") && is_file($asset->getFileSystemPath())) { $supportedTypes = [IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM]; if (in_array(@exif_imagetype($asset->getFileSystemPath()), $supportedTypes)) { $exif = @exif_read_data($asset->getFileSystemPath()); if (is_array($exif)) { $imageInfo["exif"] = []; foreach ($exif as $name => $value) { if (is_string($value) && strlen($value) < 50 || is_numeric($value)) { // this is to ensure that the data can be converted to json (must be utf8) if (mb_check_encoding($value, "UTF-8")) { $imageInfo["exif"][$name] = $value; } } } } } } $asset->imageInfo = $imageInfo; } $asset->setStream(null); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new Model\Tool\Admin\EventDataContainer(object2array($asset)); \Pimcore::getEventManager()->trigger("admin.asset.get.preSendData", $this, ["asset" => $asset, "returnValueContainer" => $returnValueContainer]); if ($asset->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(["success" => false, "message" => "missing_permission"]); }