public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document"))); } Element\Editlock::lock($this->getParam("id"), "document"); $snippet = Document\Snippet::getById($this->getParam("id")); $modificationDate = $snippet->getModificationDate(); $snippet = $this->getLatestVersion($snippet); $snippet->setVersions(array_splice($snippet->getVersions(), 0, 1)); $snippet->getScheduledTasks(); $snippet->idPath = Element\Service::getIdPath($snippet); $snippet->userPermissions = $snippet->getUserPermissions(); $snippet->setLocked($snippet->isLocked()); $snippet->setParent(null); if ($snippet->getContentMasterDocument()) { $snippet->contentMasterDocumentPath = $snippet->getContentMasterDocument()->getRealFullPath(); } $this->minimizeProperties($snippet); // unset useless data $snippet->setElements(null); if ($snippet->isAllowed("view")) { $this->_helper->json($snippet); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]); } Element\Editlock::lock($this->getParam("id"), "document"); $link = Document\Hardlink::getById($this->getParam("id")); $link = clone $link; $link->idPath = Element\Service::getIdPath($link); $link->userPermissions = $link->getUserPermissions(); $link->setLocked($link->isLocked()); $link->setParent(null); if ($link->getSourceDocument()) { $link->sourcePath = $link->getSourceDocument()->getRealFullPath(); } $this->addTranslationsData($link); $this->minimizeProperties($link); //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 \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($link)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $link, "returnValueContainer" => $returnValueContainer]); if ($link->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]); } Element\Editlock::lock($this->getParam("id"), "document"); $email = Document\Newsletter::getById($this->getParam("id")); $email = clone $email; $email = $this->getLatestVersion($email); $versions = Element\Service::getSafeVersionInfo($email->getVersions()); $email->setVersions(array_splice($versions, 0, 1)); $email->idPath = Element\Service::getIdPath($email); $email->userPermissions = $email->getUserPermissions(); $email->setLocked($email->isLocked()); $email->setParent(null); // unset useless data $email->setElements(null); $email->childs = null; $this->addTranslationsData($email); $this->minimizeProperties($email); //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 \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($email)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $email, "returnValueContainer" => $returnValueContainer]); if ($email->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document"))); } Element\Editlock::lock($this->getParam("id"), "document"); $page = Document\Page::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setVersions(array_splice($page->getVersions(), 0, 1)); $page->getScheduledTasks(); $page->idPath = Element\Service::getIdPath($page); $page->userPermissions = $page->getUserPermissions(); $page->setLocked($page->isLocked()); $page->setParent(null); if ($page->getContentMasterDocument()) { $page->contentMasterDocumentPath = $page->getContentMasterDocument()->getRealFullPath(); } // get depending redirects $redirectList = new Redirect\Listing(); $redirectList->setCondition("target = ?", $page->getId()); $page->redirects = $redirectList->load(); // unset useless data $page->setElements(null); $page->childs = null; // cleanup properties $this->minimizeProperties($page); if ($page->isAllowed("view")) { $this->_helper->json($page); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (\Pimcore\Model\Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => \Pimcore\Model\Element\Editlock::getByElement($this->getParam("id"), "document")]); } \Pimcore\Model\Element\Editlock::lock($this->getParam("id"), "document"); $page = Document\Printpage::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->getVersions(); $page->getScheduledTasks(); $page->idPath = Service::getIdPath($page); $page->userPermissions = $page->getUserPermissions(); $page->setLocked($page->isLocked()); if ($page->getContentMasterDocument()) { $page->contentMasterDocumentPath = $page->getContentMasterDocument()->getRealFullPath(); } $this->addTranslationsData($page); // unset useless data $page->setElements(null); $page->childs = null; // cleanup properties $this->minimizeProperties($page); //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 \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($page)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $page, "returnValueContainer" => $returnValueContainer]); if ($page->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function getIdPathAction() { $id = (int) $this->getParam("id"); $type = $this->getParam("type"); $response = array("success" => true); if ($element = Element\Service::getElementById($type, $id)) { $response["idPath"] = Element\Service::getIdPath($element); } $this->_helper->json($response); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document"))); } Element\Editlock::lock($this->getParam("id"), "document"); $folder = Document\Folder::getById($this->getParam("id")); $folder->idPath = Element\Service::getIdPath($folder); $folder->userPermissions = $folder->getUserPermissions(); $folder->setLocked($folder->isLocked()); $folder->setParent(null); $this->minimizeProperties($folder); if ($folder->isAllowed("view")) { $this->_helper->json($folder); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document"))); } Element\Editlock::lock($this->getParam("id"), "document"); $email = Document\Email::getById($this->getParam("id")); $email = $this->getLatestVersion($email); $email->setVersions(array_splice($email->getVersions(), 0, 1)); $email->idPath = Element\Service::getIdPath($email); $email->userPermissions = $email->getUserPermissions(); $email->setLocked($email->isLocked()); $email->setParent(null); // unset useless data $email->setElements(null); $email->childs = null; // cleanup properties $this->minimizeProperties($email); if ($email->isAllowed("view")) { $this->_helper->json($email); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (\Pimcore\Model\Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => \Pimcore\Model\Element\Editlock::getByElement($this->getParam("id"), "document")]); } \Pimcore\Model\Element\Editlock::lock($this->getParam("id"), "document"); $page = Document\Printpage::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->getVersions(); $page->getScheduledTasks(); $page->idPath = Service::getIdPath($page); $page->userPermissions = $page->getUserPermissions(); $page->setLocked($page->isLocked()); // unset useless data $page->setElements(null); $page->childs = null; // cleanup properties $this->minimizeProperties($page); if ($page->isAllowed("view")) { $this->_helper->json($page); } $this->_helper->json(false); }
public function getFolderAction() { // 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"))); if ($object->isAllowed("view")) { $objectData = array(); $objectData["general"] = array(); $objectData["idPath"] = Element\Service::getIdPath($object); $allowedKeys = array("o_published", "o_key", "o_id", "o_type", "o_path", "o_modificationDate", "o_creationDate", "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"]["fullpath"] = $object->getFullPath(); $objectData["general"]["o_locked"] = $object->isLocked(); $objectData["properties"] = Element\Service::minimizePropertiesForEditmode($object->getProperties()); $objectData["userPermissions"] = $object->getUserPermissions(); $objectData["classes"] = $object->getDao()->getClasses(); // grid-config $configFile = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $object->getId() . "-user_" . $this->getUser()->getId() . ".psf"; if (is_file($configFile)) { $gridConfig = Tool\Serialize::unserialize(file_get_contents($configFile)); if ($gridConfig) { $objectData["selectedClass"] = $gridConfig["classId"]; } } $this->_helper->json($objectData); } else { \Logger::debug("prevented getting folder id [ " . $object->getId() . " ] because of missing permissions"); $this->_helper->json(array("success" => false, "message" => "missing_permission")); } }
/** * @param AbstractObject $object * @return array */ public static function gridObjectData($object, $fields = null) { $localizedPermissionsResolved = false; $data = Element\Service::gridElementData($object); if ($object instanceof Concrete) { $data["classname"] = $object->getClassName(); $data["idPath"] = Element\Service::getIdPath($object); $data['inheritedFields'] = array(); $user = AdminTool::getCurrentUser(); //TODO keep this for later! // if (!$user->isAdmin()) { // $permissionSet = $object->getPermissions(null, $user); // $fieldPermissions = self::getFieldPermissions($object, $permissionSet); // } if (empty($fields)) { $fields = array_keys($object->getclass()->getFieldDefinitions()); } foreach ($fields as $key) { $brickType = null; $brickGetter = null; $dataKey = $key; $keyParts = explode("~", $key); $def = $object->getClass()->getFieldDefinition($key); if (substr($key, 0, 1) == "~") { $type = $keyParts[1]; if ($type == "keyvalue") { $field = $keyParts[2]; $keyid = $keyParts[3]; $getter = "get" . ucfirst($field); if (method_exists($object, $getter)) { $keyValuePairs = $object->{$getter}(); if ($keyValuePairs) { // get with inheritance $props = $keyValuePairs->getProperties(); foreach ($props as $pair) { if ($pair["key"] == $keyid) { if (isset($pair["translated"])) { if (isset($data['#kv-tr'][$dataKey])) { if (!is_array($data['#kv-tr'][$dataKey])) { $arr = array($data['#kv-tr'][$dataKey]); $data['#kv-tr'][$dataKey] = $arr; } $data['#kv-tr'][$dataKey][] = $pair["translated"]; } else { $data['#kv-tr'][$dataKey] = $pair["translated"]; } } if (isset($data[$dataKey])) { if (!is_array($data[$dataKey])) { $arr = array($data[$dataKey]); $data[$dataKey] = $arr; } $data[$dataKey][] = $pair["value"]; } else { $data[$dataKey] = $pair["value"]; } if ($pair["inherited"]) { $data['inheritedFields'][$dataKey] = array("inherited" => $pair["inherited"], "objectid" => $pair["source"]); } // break; } } } } } } else { if (count($keyParts) > 1) { // brick $brickType = $keyParts[0]; $brickKey = $keyParts[1]; $key = self::getFieldForBrickType($object->getclass(), $brickType); $brickClass = Objectbrick\Definition::getByKey($brickType); $def = $brickClass->getFieldDefinition($brickKey); } } if (!empty($key)) { // some of the not editable field require a special response $getter = "get" . ucfirst($key); $brickGetter = null; if (!empty($brickKey)) { $brickGetter = "get" . ucfirst($brickKey); } $needLocalizedPermissions = false; // if the definition is not set try to get the definition from localized fields if (!$def) { if ($locFields = $object->getClass()->getFieldDefinition("localizedfields")) { $def = $locFields->getFieldDefinition($key); if ($def) { $needLocalizedPermissions = true; } } } //relation type fields with remote owner do not have a getter if (method_exists($object, $getter)) { //system columns must not be inherited if (in_array($key, Concrete::$systemColumnNames)) { $data[$dataKey] = $object->{$getter}(); } else { $valueObject = self::getValueForObject($object, $key, $brickType, $brickKey, $def); $data['inheritedFields'][$dataKey] = array("inherited" => $valueObject->objectid != $object->getId(), "objectid" => $valueObject->objectid); if (method_exists($def, "getDataForGrid")) { $tempData = $def->getDataForGrid($valueObject->value, $object); if ($def instanceof ClassDefinition\Data\Localizedfields) { $needLocalizedPermissions = true; foreach ($tempData as $tempKey => $tempValue) { $data[$tempKey] = $tempValue; } } else { $data[$dataKey] = $tempData; } } else { $data[$dataKey] = $valueObject->value; } } } if ($needLocalizedPermissions) { if (!$user->isAdmin()) { /** @var $locale \Zend_Locale */ $locale = (string) \Zend_Registry::get("Zend_Locale"); $permissionTypes = array("View", "Edit"); foreach ($permissionTypes as $permissionType) { //TODO, this needs refactoring! Ideally, call it only once! $languagesAllowed = self::getLanguagePermissions($object, $user, "l" . $permissionType); if ($languagesAllowed) { $languagesAllowed = array_keys($languagesAllowed); if (!in_array($locale, $languagesAllowed)) { $data["metadata"]["permission"][$key]["no" . $permissionType] = 1; if ($permissionType == "View") { $data[$key] = null; } } } } } } } } } return $data; }
public function typePathAction() { $id = $this->getParam("id"); $type = $this->getParam("type"); $data = []; if ($type == "asset") { $element = Asset::getById($id); } elseif ($type == "document") { $element = Document::getById($id); $data["index"] = $element->getIndex(); } else { $element = Object::getById($id); } $typePath = Element\Service::getTypePath($element); $data["success"] = true; $data["idPath"] = Element\Service::getIdPath($element); $data["typePath"] = $typePath; $data["fullpath"] = $element->getRealFullPath(); $this->_helper->json($data); }
public function gridProxyAction() { if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { //TODO probably not needed } } else { $db = \Pimcore\Resource::get(); // get list of objects $folder = Asset::getById($this->getParam("folderId")); $start = 0; $limit = 20; $orderKey = "id"; $order = "ASC"; if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } if ($this->getParam("dir")) { $order = $this->getParam("dir"); } if ($this->getParam("sort")) { $orderKey = $this->getParam("sort"); if ($orderKey == "fullpath") { $orderKey = array("path", "filename"); } } $conditionFilters = array(); if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "parentId = " . $folder->getId(); } else { $conditionFilters[] = "path LIKE '" . ($folder->getFullPath() == "/" ? "/%'" : $folder->getFullPath() . "/%'"); } $conditionFilters[] = "type != 'folder'"; $filterJson = $this->getParam("filter"); if ($filterJson) { $filters = \Zend_Json::decode($filterJson); foreach ($filters as $filter) { $operator = "="; if ($filter["type"] == "string") { $operator = "LIKE"; } else { if ($filter["type"] == "numeric") { if ($filter["comparison"] == "lt") { $operator = "<"; } else { if ($filter["comparison"] == "gt") { $operator = ">"; } else { if ($filter["comparison"] == "eq") { $operator = "="; } } } } else { if ($filter["type"] == "date") { if ($filter["comparison"] == "lt") { $operator = "<"; } else { if ($filter["comparison"] == "gt") { $operator = ">"; } else { if ($filter["comparison"] == "eq") { $operator = "="; } } } $filter["value"] = strtotime($filter["value"]); } else { if ($filter["type"] == "list") { $operator = "="; } else { if ($filter["type"] == "boolean") { $operator = "="; $filter["value"] = (int) $filter["value"]; } } } } } // system field $value = $filter["value"]; if ($operator == "LIKE") { $value = "%" . $value . "%"; } $field = "`" . $filter["field"] . "` "; if ($filter["field"] == "fullpath") { $field = "CONCAT(path,filename)"; } $conditionFilters[] = $field . $operator . " " . $db->quote($value); } } $list = new Asset\Listing(); $condition = implode(" AND ", $conditionFilters); $list->setCondition($condition); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $list->load(); $assets = array(); foreach ($list->getAssets() as $asset) { /** @var $asset Asset */ $filename = PIMCORE_ASSET_DIRECTORY . "/" . $asset->getFullPath(); $size = filesize($filename); $assets[] = array("id" => $asset->getid(), "type" => $asset->getType(), "fullpath" => $asset->getFullPath(), "creationDate" => $asset->getCreationDate(), "modificationDate" => $asset->getModificationDate(), "size" => formatBytes($size), "idPath" => $data["idPath"] = Element\Service::getIdPath($asset)); } $this->_helper->json(array("data" => $assets, "success" => true, "total" => $list->getTotalCount())); } }