/** * @return Tool\User * @throws \Exception */ public function getUser() { if ($user = Tool\Admin::getCurrentUser()) { return $user; } throw new \Exception("Webservice instantiated, but no user present"); }
/** * @param $class * @param $json * @return bool */ public static function importClassDefinitionFromJson($class, $json, $throwException = false) { $userId = 0; $user = \Pimcore\Tool\Admin::getCurrentUser(); if ($user) { $userId = $user->getId(); } $importData = \Zend_Json::decode($json); // set layout-definition $layout = self::generateLayoutTreeFromArray($importData["layoutDefinitions"], $throwException); if ($layout === false) { return false; } $class->setLayoutDefinitions($layout); // set properties of class $class->setModificationDate(time()); $class->setUserModification($userId); $class->setIcon($importData["icon"]); $class->setAllowInherit($importData["allowInherit"]); $class->setAllowVariants($importData["allowVariants"]); $class->setShowVariants($importData["showVariants"]); $class->setParentClass($importData["parentClass"]); $class->setUseTraits($importData["useTraits"]); $class->setPreviewUrl($importData["previewUrl"]); $class->setPropertyVisibility($importData["propertyVisibility"]); $class->save(); return true; }
private function checkUserPermission($permission) { if ($user = Tool\Admin::getCurrentUser()) { if ($user->isAllowed($permission)) { return; } } $this->getResponse()->setHttpResponseCode(403); $this->encoder->encode(["success" => false, "msg" => "not allowed"]); }
/** * @param $id * @param bool $create * @param bool $returnIdIfEmpty * @param null $language * @return array * @throws \Exception * @throws \Zend_Exception */ public static function getByKeyLocalized($id, $create = false, $returnIdIfEmpty = false, $language = null) { if ($user = Tool\Admin::getCurrentUser()) { $language = $user->getLanguage(); } elseif ($user = Tool\Authentication::authenticateSession()) { $language = $user->getLanguage(); } elseif (\Zend_Registry::isRegistered("Zend_Locale")) { $language = (string) \Zend_Registry::get("Zend_Locale"); } if (!in_array($language, Tool\Admin::getLanguages())) { $config = \Pimcore\Config::getSystemConfig(); $language = $config->general->language; } return self::getByKey($id, $create, $returnIdIfEmpty)->getTranslation($language); }
public function init() { parent::init(); $pimUser = false; if (\Pimcore\Tool::isFrontentRequestByAdmin()) { $pimUser = \Pimcore\Tool\Admin::getCurrentUser(); if ($pimUser) { //echo "IS ADMIN"; } } $identity = \Zend_Auth::getInstance()->getIdentity(); if (!$identity && !$pimUser or $this->getParam('oid') != $identity['oid']) { $this->redirect("/"); } else { // login ok } }
/** * Moves a file/directory * * @param string $sourcePath * @param string $destinationPath * @return void */ public function move($sourcePath, $destinationPath) { $nameParts = explode("/", $sourcePath); $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]); $sourcePath = implode("/", $nameParts); $nameParts = explode("/", $destinationPath); $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]); $destinationPath = implode("/", $nameParts); try { if (dirname($sourcePath) == dirname($destinationPath)) { $asset = null; if ($asset = Asset::getByPath("/" . $destinationPath)) { // If we got here, this means the destination exists, and needs to be overwritten $sourceAsset = Asset::getByPath("/" . $sourcePath); $asset->setData($sourceAsset->getData()); $sourceAsset->delete(); } // see: Asset\WebDAV\File::delete() why this is necessary $log = Asset\WebDAV\Service::getDeleteLog(); if (!$asset && array_key_exists("/" . $destinationPath, $log)) { $asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]); if ($asset) { $sourceAsset = Asset::getByPath("/" . $sourcePath); $asset->setData($sourceAsset->getData()); $sourceAsset->delete(); } } if (!$asset) { $asset = Asset::getByPath("/" . $sourcePath); } $asset->setFilename(basename($destinationPath)); } else { $asset = Asset::getByPath("/" . $sourcePath); $parent = Asset::getByPath("/" . dirname($destinationPath)); $asset->setPath($parent->getFullPath() . "/"); $asset->setParentId($parent->getId()); } $user = \Pimcore\Tool\Admin::getCurrentUser(); $asset->setUserModification($user->getId()); $asset->save(); } catch (\Exception $e) { \Logger::error($e); } }
/** * Creates a note for an action with a transition * @param Element\AbstractElement $element * @param string $type * @param string $title * @param string $description * @param array $noteData * @return Element\Note $note */ public static function createActionNote($element, $type, $title, $description, $noteData, $user = null) { //prepare some vars for creating the note if (!$user) { $user = \Pimcore\Tool\Admin::getCurrentUser(); } $note = new Element\Note(); $note->setElement($element); $note->setDate(time()); $note->setType($type); $note->setTitle($title); $note->setDescription($description); $note->setUser($user->getId()); if (is_array($noteData)) { foreach ($noteData as $row) { $note->addData($row['key'], $row['type'], $row['value']); } } $note->save(); return $note; }
/** * Fired before information is sent back to the admin UI about an element * @param \Zend_EventManager_Event $e * @throws \Exception */ public static function adminElementGetPreSendData($e) { $element = self::extractElementFromEvent($e); $returnValueContainer = $e->getParam('returnValueContainer'); $data = $returnValueContainer->getData(); //create a new namespace for WorkflowManagement //set some defaults $data['workflowManagement'] = ['hasWorkflowManagement' => false]; if (Workflow\Manager::elementCanAction($element)) { $data['workflowManagement']['hasWorkflowManagement'] = true; //see if we can change the layout $currentUser = Admin::getCurrentUser(); $manager = Workflow\Manager\Factory::getManager($element, $currentUser); $data['workflowManagement']['workflowName'] = $manager->getWorkflow()->getName(); //get the state and status $state = $manager->getElementState(); $data['workflowManagement']['state'] = $manager->getWorkflow()->getStateConfig($state); $status = $manager->getElementStatus(); $data['workflowManagement']['status'] = $manager->getWorkflow()->getStatusConfig($status); if ($element instanceof ConcreteObject) { $workflowLayoutId = $manager->getObjectLayout(); //check for !is_null here as we might want to specify 0 in the workflow config if (!is_null($workflowLayoutId)) { //load the new layout into the object container $validLayouts = Object\Service::getValidLayouts($element); //check that the layout id is valid before trying to load if (!empty($validLayouts)) { //todo check user permissions again if ($validLayouts && $validLayouts[$workflowLayoutId]) { $customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId); $customLayoutDefinition = $customLayout->getLayoutDefinitions(); Object\Service::enrichLayoutDefinition($customLayoutDefinition, $e->getParam('object')); $data["layout"] = $customLayoutDefinition; } } } } } $returnValueContainer->setData($data); }
</head> <body> <!-- Fixed navbar --> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <a href="#" class="navbar-brand dropdown-toggle"><span class="glyphicon glyphicon-shopping-cart"></span> Online-Shop Back Office</span></a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <?php $user = \Pimcore\Tool\Admin::getCurrentUser(); $currentAction = Zend_Controller_Front::getInstance()->getRequest()->getActionName(); $currentController = Zend_Controller_Front::getInstance()->getRequest()->getControllerName(); $arrActions = []; if ($user->isAllowed('plugin_onlineshop_back-office_order')) { $arrActions['order'][] = 'list'; } foreach ($arrActions as $controller => $actions) { foreach ($actions as $action) { ?> <li class="<?php echo $currentController == 'admin-' . $controller && $currentAction == $action ? 'active' : ''; ?> "> <a href="<?php echo $this->url(['action' => $action, 'controller' => 'admin-' . $controller, 'module' => 'OnlineShop'], null, true);
/** * @param mixed $value * @param null $object * @param null $idMapper * @return mixed|null|Object\Localizedfield * @throws \Exception */ public function getFromWebserviceImport($value, $object = null, $idMapper = null) { if (is_array($value)) { $validLanguages = Tool::getValidLanguages(); if (!$idMapper || !$idMapper->ignoreMappingFailures()) { foreach ($value as $v) { if (!in_array($v->language, $validLanguages)) { throw new \Exception("Invalid language in localized fields"); } } } $localizedFields = $object->getLocalizedFields(); if (!$localizedFields) { $localizedFields = new Object\Localizedfield(); } if ($object instanceof Object\Concrete) { $localizedFields->setObject($object); } $user = Tool\Admin::getCurrentUser(); $languagesAllowed = null; if ($user && !$user->isAdmin()) { $languagesAllowed = Object\Service::getLanguagePermissions($object, $user, "lEdit"); if ($languagesAllowed) { $languagesAllowed = array_keys($languagesAllowed); } } foreach ($value as $field) { if ($field instanceof \stdClass) { $field = Tool\Cast::castToClass("\\Pimcore\\Model\\Webservice\\Data\\Object\\Element", $field); } if ($idMapper && $idMapper->ignoreMappingFailures()) { if (!in_array($field->language, $validLanguages)) { continue; } } if ($languagesAllowed && !in_array($field->language, $languagesAllowed)) { //TODO needs to be discussed. Maybe it is better to throw an exception instead of ignoring //the language continue; } if (!$field instanceof Model\Webservice\Data\Object\Element) { throw new \Exception("Invalid import data in field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]"); } $fd = $this->getFielddefinition($field->name); if (!$fd instanceof Object\ClassDefinition\Data) { if ($idMapper && $idMapper->ignoreMappingFailures()) { continue; } throw new \Exception("Unknown field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ] "); } else { if ($fd->getFieldtype() != $field->type) { throw new \Exception("Type mismatch for field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]. Should be [ " . $fd->getFieldtype() . " ], but is [ " . $field->type . " ] "); } } $localizedFields->setLocalizedValue($field->name, $this->getFielddefinition($field->name)->getFromWebserviceImport($field->value, $object, $idMapper), $field->language); } return $localizedFields; } else { if (!empty($value)) { throw new \Exception("Invalid data in localized fields"); } else { return null; } } }
public function fieldcollectionListAction() { $user = \Pimcore\Tool\Admin::getCurrentUser(); $currentLayoutId = $this->getParam("layoutId"); $list = new Object\Fieldcollection\Definition\Listing(); $list = $list->load(); if ($this->hasParam("allowedTypes")) { $filteredList = []; $allowedTypes = explode(",", $this->getParam("allowedTypes")); /** @var $type Object\Fieldcollection\Definition */ foreach ($list as $type) { if (in_array($type->getKey(), $allowedTypes)) { $filteredList[] = $type; // mainly for objects-meta data-type $layoutDefinitions = $type->getLayoutDefinitions(); Object\Service::enrichLayoutDefinition($layoutDefinitions, null); if ($currentLayoutId == -1 && $user->isAdmin()) { Object\Service::createSuperLayout($layoutDefinitions); } } } $list = $filteredList; } $this->_helper->json(["fieldcollections" => $list]); }
?> , google_webmastertools_enabled: <?php echo \Zend_Json::encode((bool) \Pimcore\Google\Webmastertools::isConfigured()); ?> , customviews: <?php echo \Zend_Json::encode($this->customview_config); ?> , language: '<?php echo $this->language; ?> ', websiteLanguages: <?php echo \Zend_Json::encode(explode(",", \Pimcore\Tool\Admin::reorderWebsiteLanguages(\Pimcore\Tool\Admin::getCurrentUser(), $this->config->general->validLanguages))); ?> , google_translate_api_key: "<?php echo $this->config->services->translate->apikey; ?> ", google_maps_api_key: "<?php echo $googleMapsApiKey; ?> ", showCloseConfirmation: true, debug_admin_translations: <?php echo \Zend_Json::encode((bool) $this->config->general->debug_admin_translations); ?> ,
/** Gets the active perspective for the current user * @return array */ public static function getRuntimePerspective() { $currentUser = Tool\Admin::getCurrentUser(); $currentConfigName = $currentUser->getActivePerspective() ? $currentUser->getActivePerspective() : $currentUser->getFirstAllowedPerspective(); $config = self::getPerspectivesConfig()->toArray(); $result = []; if ($config[$currentConfigName]) { $result = $config[$currentConfigName]; } else { $availablePerspectives = self::getAvailablePerspectives($currentUser); if ($availablePerspectives) { $currentPerspective = reset($availablePerspectives); $currentConfigName = $currentPerspective["name"]; if ($currentConfigName && $config[$currentConfigName]) { $result = $config[$currentConfigName]; } } } if ($result && $currentConfigName != $currentUser->getActivePerspective()) { $currentUser->setActivePerspective($currentConfigName); $currentUser->save(); } $result["elementTree"] = self::getRuntimeElementTreeConfig($currentConfigName); return $result; }
/** Determines the custom layout definition (if necessary) for the given class * @param ClassDefinition $class * @param int $objectId * @return array layout */ public static function getCustomLayoutDefinitionForGridColumnConfig(ClassDefinition $class, $objectId) { $layoutDefinitions = $class->getLayoutDefinitions(); $result = array("layoutDefinition" => $layoutDefinitions); if (!$objectId) { return $result; } $user = AdminTool::getCurrentUser(); if ($user->isAdmin()) { return $result; } $mergedFieldDefinition = self::getCustomGridFieldDefinitions($class->getId(), $objectId); if (is_array($mergedFieldDefinition)) { if ($mergedFieldDefinition["localizedfields"]) { $childs = $mergedFieldDefinition["localizedfields"]->getFieldDefinitions(); if (is_array($childs)) { foreach ($childs as $locKey => $locValue) { $mergedFieldDefinition[$locKey] = $locValue; } } } self::doFilterCustomGridFieldDefinitions($layoutDefinitions, $mergedFieldDefinition); $result["layoutDefinition"] = $layoutDefinitions; $result["fieldDefinition"] = $mergedFieldDefinition; } return $result; }
/** * @param resource $data * @throws DAV\Exception\Forbidden * @throws \Exception */ function put($data) { if ($this->asset->isAllowed("publish")) { // read from resource -> default for SabreDAV $tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/asset-dav-tmp-file-" . uniqid(); file_put_contents($tmpFile, $data); $file = fopen($tmpFile, "r+"); $user = AdminTool::getCurrentUser(); $this->asset->setUserModification($user->getId()); $this->asset->setStream($file); $this->asset->save(); fclose($file); unlink($tmpFile); } else { throw new DAV\Exception\Forbidden(); } }
public function gridProxyAction() { $requestedLanguage = $this->getParam("language"); if ($requestedLanguage) { if ($requestedLanguage != "default") { $this->setLanguage($requestedLanguage, true); } } else { $requestedLanguage = $this->getLanguage(); } if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { try { $data = \Zend_Json::decode($this->getParam("data")); // save $object = Object::getById($data["id"]); /** @var Object\ClassDefinition $class */ $class = $object->getClass(); if (!$object->isAllowed("publish")) { throw new \Exception("Permission denied. You don't have the rights to save this object."); } $user = Tool\Admin::getCurrentUser(); $allLanguagesAllowed = false; if (!$user->isAdmin()) { $languagePermissions = $object->getPermissions("lEdit", $user); //sets allowed all languages modification when the lEdit column is empty $allLanguagesAllowed = $languagePermissions["lEdit"] == ''; $languagePermissions = explode(",", $languagePermissions["lEdit"]); } $objectData = []; foreach ($data as $key => $value) { $parts = explode("~", $key); if (substr($key, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; if ($type == "classificationstore") { $groupKeyId = explode("-", $keyid); $groupId = $groupKeyId[0]; $keyid = $groupKeyId[1]; $getter = "get" . ucfirst($field); if (method_exists($object, $getter)) { /** @var $classificationStoreData Object\Classificationstore */ $classificationStoreData = $object->{$getter}(); $classificationStoreData->setLocalizedKeyValue($groupId, $keyid, $value, $requestedLanguage); } } else { $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } } elseif (count($parts) > 1) { $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brick->{$valueSetter}($value); } else { if (!$user->isAdmin() && $languagePermissions) { $fd = $class->getFieldDefinition($key); if (!$fd) { // try to get via localized fields $localized = $class->getFieldDefinition("localizedfields"); if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) { $field = $localized->getFieldDefinition($key); if ($field) { $currentLocale = (string) \Zend_Registry::get("Zend_Locale"); if (!$allLanguagesAllowed && !in_array($currentLocale, $languagePermissions)) { continue; } } } } } $objectData[$key] = $value; } } $object->setValues($objectData); $object->save(); $this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields"), $requestedLanguage), "success" => true]); } catch (\Exception $e) { $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } else { // get list of objects $folder = Object::getById($this->getParam("folderId")); $class = Object\ClassDefinition::getById($this->getParam("classId")); $className = $class->getName(); $colMappings = ["filename" => "o_key", "fullpath" => ["o_path", "o_key"], "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"]; $start = 0; $limit = 20; $orderKey = "o_id"; $order = "ASC"; $fields = []; $bricks = []; if ($this->getParam("fields")) { $fields = $this->getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); $sub = substr($f, 0, 1); if (substr($f, 0, 1) == "~") { $type = $parts[1]; // $field = $parts[2]; // $keyid = $parts[3]; // key value, ignore for now if ($type == "classificationstore") { } } elseif (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); $doNotQuote = false; if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if (strlen($sortingSettings['orderKey']) > 0) { $orderKey = $sortingSettings['orderKey']; if (!(substr($orderKey, 0, 1) == "~")) { if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } elseif ($class->getFieldDefinition($orderKey) instanceof Object\ClassDefinition\Data\QuantityValue) { $orderKey = "concat(" . $orderKey . "__unit, " . $orderKey . "__value)"; $doNotQuote = true; } elseif (strpos($orderKey, "~") !== false) { $orderKeyParts = explode("~", $orderKey); if (count($orderKeyParts) == 2) { $orderKey = $orderKeyParts[1]; } } } } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = []; if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "o_parentId = " . $folder->getId(); } else { $conditionFilters[] = "(o_path = '" . $folder->getRealFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getRealFullPath() . "/") . "%')"; } if (!$this->getUser()->isAdmin()) { $userIds = $this->getUser()->getRoles(); $userIds[] = $this->getUser()->getId(); $conditionFilters[] .= " (\n (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(o_path,o_key),cpath)=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n OR\n (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(o_path,o_key))=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n )"; } $featureJoins = []; $featureFilters = false; // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); $featureFilters = Object\Service::getFeatureFilters($this->getParam("filter"), $class); if ($featureFilters) { $featureJoins = array_merge($featureJoins, $featureFilters["joins"]); } } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); if (isset($sortingSettings["isFeature"]) && $sortingSettings["isFeature"]) { $orderKey = "cskey_" . $sortingSettings["fieldname"] . "_" . $sortingSettings["groupId"] . "_" . $sortingSettings["keyId"]; $list->setOrderKey($orderKey); $list->setGroupBy("o_id"); $featureJoins[] = $sortingSettings; } else { $list->setOrderKey($orderKey, !$doNotQuote); } $list->setOrder($order); if ($class->getShowVariants()) { $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT]); } Object\Service::addGridFeatureJoins($list, $featureJoins, $class, $featureFilters, $requestedLanguage); $list->load(); $objects = []; foreach ($list->getObjects() as $object) { $o = Object\Service::gridObjectData($object, $fields, $requestedLanguage); $objects[] = $o; } $this->_helper->json(["data" => $objects, "success" => true, "total" => $list->getTotalCount()]); } }
/** * @param string $name * @throws DAV\Exception\Forbidden */ function createDirectory($name) { $user = AdminTool::getCurrentUser(); if ($this->asset->isAllowed("create")) { $asset = Asset::create($this->asset->getId(), array("filename" => File::getValidFilename($name), "type" => "folder", "userModification" => $user->getId(), "userOwner" => $user->getId())); } else { throw new DAV\Exception\Forbidden(); } }
/** * @param string $name * @throws DAV\Exception\Forbidden */ public function createDirectory($name) { $user = AdminTool::getCurrentUser(); if ($this->asset->isAllowed("create")) { $asset = Asset::create($this->asset->getId(), ["filename" => Element\Service::getValidKey($name, "asset"), "type" => "folder", "userModification" => $user->getId(), "userOwner" => $user->getId()]); } else { throw new DAV\Exception\Forbidden(); } }
/** * Updates the paths for children, children's properties and children's permissions in the database * * @param string $oldPath * @return void */ public function updateChildsPaths($oldPath) { if ($this->hasChilds()) { //get objects to empty their cache $objects = $this->db->fetchCol("SELECT o_id FROM objects WHERE o_path LIKE ?", $oldPath . "%"); $userId = "0"; if ($user = \Pimcore\Tool\Admin::getCurrentUser()) { $userId = $user->getId(); } //update object child paths $this->db->query("update objects set o_path = replace(o_path," . $this->db->quote($oldPath . "/") . "," . $this->db->quote($this->model->getFullPath() . "/") . "), o_modificationDate = '" . time() . "', o_userModification = '" . $userId . "' where o_path like " . $this->db->quote($oldPath . "/%") . ";"); //update object child permission paths $this->db->query("update users_workspaces_object set cpath = replace(cpath," . $this->db->quote($oldPath . "/") . "," . $this->db->quote($this->model->getFullPath() . "/") . ") where cpath like " . $this->db->quote($oldPath . "/%") . ";"); //update object child properties paths $this->db->query("update properties set cpath = replace(cpath," . $this->db->quote($oldPath . "/") . "," . $this->db->quote($this->model->getFullPath() . "/") . ") where cpath like " . $this->db->quote($oldPath . "/%") . ";"); return $objects; } }
/** * */ public function restore($user = null) { $raw = file_get_contents($this->getStoreageFile()); $element = Serialize::unserialize($raw); // check for element with the same name if ($element instanceof Document) { $indentElement = Document::getByPath($element->getRealFullPath()); if ($indentElement) { $element->setKey($element->getKey() . "_restore"); } } elseif ($element instanceof Asset) { $indentElement = Asset::getByPath($element->getRealFullPath()); if ($indentElement) { $element->setFilename($element->getFilename() . "_restore"); } } elseif ($element instanceof Object\AbstractObject) { $indentElement = Object::getByPath($element->getRealFullPath()); if ($indentElement) { $element->setKey($element->getKey() . "_restore"); } } if (\Pimcore\Tool\Admin::getCurrentUser()) { $parent = $element->getParent(); if (!$parent->isAllowed("publish")) { throw new \Exception("Not sufficient permissions"); } } $this->restoreChilds($element); $this->delete(); }
public function gridGetColumnConfigAction() { if ($this->getParam("id")) { $class = Object\ClassDefinition::getById($this->getParam("id")); } else { if ($this->getParam("name")) { $class = Object\ClassDefinition::getByName($this->getParam("name")); } } $gridType = "search"; if ($this->getParam("gridtype")) { $gridType = $this->getParam("gridtype"); } $objectId = $this->getParam("objectId"); if ($objectId) { $fields = Object\Service::getCustomGridFieldDefinitions($class->getId(), $objectId); } if (!$fields) { $fields = $class->getFieldDefinitions(); } $types = array(); if ($this->getParam("types")) { $types = explode(",", $this->getParam("types")); } // grid config $gridConfig = array(); if ($objectId) { $configFiles["configFileClassUser"] = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $this->getParam("objectId") . "_" . $class->getId() . "-user_" . $this->getUser()->getId() . ".psf"; $configFiles["configFileUser"] = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $this->getParam("objectId") . "-user_" . $this->getUser()->getId() . ".psf"; foreach ($configFiles as $configFile) { if (is_file($configFile)) { $gridConfig = Tool\Serialize::unserialize(file_get_contents($configFile)); if (is_array($gridConfig) && array_key_exists("classId", $gridConfig)) { if ($gridConfig["classId"] == $class->getId()) { break; } else { $gridConfig = array(); } } else { break; } } } } $localizedFields = array(); $objectbrickFields = array(); foreach ($fields as $key => $field) { if ($field instanceof Object\ClassDefinition\Data\Localizedfields) { $localizedFields[] = $field; } else { if ($field instanceof Object\ClassDefinition\Data\Objectbricks) { $objectbrickFields[] = $field; } } } $availableFields = array(); $systemColumns = array("id", "fullpath", "published", "creationDate", "modificationDate", "filename", "classname"); if (empty($gridConfig)) { $count = 0; if (!$this->getParam("no_system_columns")) { $vis = $class->getPropertyVisibility(); foreach ($systemColumns as $sc) { $key = $sc; if ($key == "fullpath") { $key = "path"; } if (empty($types) && ($vis[$gridType][$key] || $gridType == "all")) { $availableFields[] = array("key" => $sc, "type" => "system", "label" => $sc, "position" => $count); $count++; } } } $includeBricks = !$this->getParam("no_brick_columns"); foreach ($fields as $key => $field) { if ($field instanceof Object\ClassDefinition\Data\Localizedfields) { foreach ($field->getFieldDefinitions() as $fd) { if (empty($types) || in_array($fd->getFieldType(), $types)) { $fieldConfig = $this->getFieldGridConfig($fd, $gridType, $count); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } } } else { if ($field instanceof Object\ClassDefinition\Data\Objectbricks && $includeBricks) { if (in_array($field->getFieldType(), $types)) { $fieldConfig = $this->getFieldGridConfig($field, $gridType, $count); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } else { $allowedTypes = $field->getAllowedTypes(); if (!empty($allowedTypes)) { foreach ($allowedTypes as $t) { $brickClass = Object\Objectbrick\Definition::getByKey($t); $brickFields = $brickClass->getFieldDefinitions(); if (!empty($brickFields)) { foreach ($brickFields as $bf) { $fieldConfig = $this->getFieldGridConfig($bf, $gridType, $count, false, $t . "~"); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } } } } } } else { if (empty($types) || in_array($field->getFieldType(), $types)) { $fieldConfig = $this->getFieldGridConfig($field, $gridType, $count, !empty($types)); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } } } } } else { $savedColumns = $gridConfig['columns']; foreach ($savedColumns as $key => $sc) { if (!$sc['hidden']) { if (in_array($key, $systemColumns)) { $colConfig = array("key" => $key, "type" => "system", "label" => $key, "position" => $sc['position']); if (isset($sc['width'])) { $colConfig['width'] = $sc['width']; } $availableFields[] = $colConfig; } else { $keyParts = explode("~", $key); if (substr($key, 0, 1) == "~") { // not needed for now // $type = $keyParts[1]; // $field = $keyParts[2]; // $keyid = $keyParts[3]; } else { if (count($keyParts) > 1) { $brick = $keyParts[0]; $key = $keyParts[1]; $brickClass = Object\Objectbrick\Definition::getByKey($brick); $fd = $brickClass->getFieldDefinition($key); if (!empty($fd)) { $fieldConfig = $this->getFieldGridConfig($fd, $gridType, $sc['position'], true, $brick . "~"); if (!empty($fieldConfig)) { if (isset($sc['width'])) { $fieldConfig['width'] = $sc['width']; } $availableFields[] = $fieldConfig; } } } else { $fd = $class->getFieldDefinition($key); //if not found, look for localized fields if (empty($fd)) { foreach ($localizedFields as $lf) { $fd = $lf->getFieldDefinition($key); if (!empty($fd)) { break; } } } if (!empty($fd)) { $fieldConfig = $this->getFieldGridConfig($fd, $gridType, $sc['position'], true); if (!empty($fieldConfig)) { if (isset($sc['width'])) { $fieldConfig['width'] = $sc['width']; } $availableFields[] = $fieldConfig; } } } } } } } } usort($availableFields, function ($a, $b) { if ($a["position"] == $b["position"]) { return 0; } return $a["position"] < $b["position"] ? -1 : 1; }); $config = \Pimcore\Config::getSystemConfig(); $frontendLanguages = Tool\Admin::reorderWebsiteLanguages(\Pimcore\Tool\Admin::getCurrentUser(), $config->general->validLanguages); if ($frontendLanguages) { $language = explode(',', $frontendLanguages)[0]; } else { $language = $this->getLanguage(); } if (!Tool::isValidLanguage($language)) { $validLanguages = Tool::getValidLanguages(); $language = $validLanguages[0]; } if (!empty($gridConfig) && !empty($gridConfig['language'])) { $language = $gridConfig['language']; } $this->_helper->json(array("sortinfo" => $gridConfig['sortinfo'], "language" => $language, "availableFields" => $availableFields, "onlyDirectChildren" => $gridConfig['onlyDirectChildren'], "pageSize" => $gridConfig['pageSize'])); }
?> , perspective: <?php echo \Zend_Json::encode($runtimePerspective); ?> , availablePerspectives: <?php echo \Zend_Json::encode(\Pimcore\Config::getAvailablePerspectives(\Pimcore\Tool\Admin::getCurrentUser())); ?> , customviews: <?php echo \Zend_Json::encode($this->customview_config); ?> , disabledPortlets: <?php echo \Zend_Json::encode((new \Pimcore\Helper\Dashboard(\Pimcore\Tool\Admin::getCurrentUser()))->getDisabledPortlets()); ?> }; </script> <?php // 3rd party libraries ?> <script type="text/javascript"> <?php if (isset($googleMapsApiKey) && strlen($googleMapsApiKey) > 0) { ?> var gmapInitialize = function () {}; // dummy callback (function() { var script = document.createElement("script");
public function save() { // check if there's a valid user if (!$this->getUser()) { // try to use the logged in user if (\Pimcore::inAdmin()) { if ($user = \Pimcore\Tool\Admin::getCurrentUser()) { $this->setUser($user->getId()); } } } $this->getResource()->save(); }
/** * @param $cid * @param $ctype * @return bool|Editlock */ public static function lock($cid, $ctype) { // try to get user if (!($user = \Pimcore\Tool\Admin::getCurrentUser())) { return false; } $lock = new self(); $lock->setCid($cid); $lock->setCtype($ctype); $lock->setDate(time()); $lock->setUserId($user->getId()); $lock->setSessionId(session_id()); $lock->save(); return $lock; }
public function gridProxyAction() { if ($this->getParam("language")) { $this->setLanguage($this->getParam("language"), true); } if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { try { $data = \Zend_Json::decode($this->getParam("data")); // save $object = Object::getById($data["id"]); /** @var Object\ClassDefinition $class */ $class = $object->getClass(); if (!$object->isAllowed("publish")) { throw new \Exception("Permission denied. You don't have the rights to save this object."); } $user = Tool\Admin::getCurrentUser(); if (!$user->isAdmin()) { $languagePermissions = $object->getPermissions("lEdit", $user); $languagePermissions = explode(",", $languagePermissions["lEdit"]); } $objectData = array(); foreach ($data as $key => $value) { $parts = explode("~", $key); if (substr($key, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } elseif (count($parts) > 1) { $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brick->{$valueSetter}($value); } else { if (!$user->isAdmin() && $languagePermissions) { $fd = $class->getFieldDefinition($key); if (!$fd) { // try to get via localized fields $localized = $class->getFieldDefinition("localizedfields"); if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) { $field = $localized->getFieldDefinition($key); if ($field) { $currentLocale = (string) \Zend_Registry::get("Zend_Locale"); if (!in_array($currentLocale, $languagePermissions)) { continue; } } } } } $objectData[$key] = $value; } } $object->setValues($objectData); $object->save(); $this->_helper->json(array("data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true)); } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } else { // get list of objects $folder = Object::getById($this->getParam("folderId")); $class = Object\ClassDefinition::getById($this->getParam("classId")); $className = $class->getName(); $colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"); $start = 0; $limit = 20; $orderKey = "o_id"; $order = "ASC"; $fields = array(); $bricks = array(); if ($this->getParam("fields")) { $fields = $this->getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); $sub = substr($f, 0, 1); if (substr($f, 0, 1) == "~") { // $type = $parts[1]; // $field = $parts[2]; // $keyid = $parts[3]; // key value, ignore for now } elseif (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if (strlen($sortingSettings['orderKey']) > 0) { $orderKey = $sortingSettings['orderKey']; if (!(substr($orderKey, 0, 1) == "~")) { if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } } } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = array(); if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "o_parentId = " . $folder->getId(); } else { $conditionFilters[] = "(o_path = '" . $folder->getFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%')"; } // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); if ($class->getShowVariants()) { $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT]); } $list->load(); $objects = array(); foreach ($list->getObjects() as $object) { $o = Object\Service::gridObjectData($object, $fields); $objects[] = $o; } $this->_helper->json(array("data" => $objects, "success" => true, "total" => $list->getTotalCount())); } }
public function updateChildsPaths($oldPath) { //get assets to empty their cache $assets = $this->db->fetchCol("SELECT id FROM assets WHERE path LIKE " . $this->db->quote($oldPath . "%")); $userId = "0"; if ($user = \Pimcore\Tool\Admin::getCurrentUser()) { $userId = $user->getId(); } //update assets child paths $this->db->query("update assets set path = replace(path," . $this->db->quote($oldPath . "/") . "," . $this->db->quote($this->model->getRealFullPath() . "/") . "), modificationDate = '" . time() . "', userModification = '" . $userId . "' where path like " . $this->db->quote($oldPath . "/%") . ";"); //update assets child permission paths $this->db->query("update users_workspaces_asset set cpath = replace(cpath," . $this->db->quote($oldPath . "/") . "," . $this->db->quote($this->model->getRealFullPath() . "/") . ") where cpath like " . $this->db->quote($oldPath . "/%") . ";"); //update assets child properties paths $this->db->query("update properties set cpath = replace(cpath," . $this->db->quote($oldPath . "/") . "," . $this->db->quote($this->model->getRealFullPath() . "/") . ") where cpath like " . $this->db->quote($oldPath . "/%") . ";"); return $assets; }
protected function populateChildNodes($node, &$currentList) { $currentUser = \Pimcore\Tool\Admin::getCurrentUser(); $list = new User\Listing(); $list->setCondition("parentId = ?", $node->getId()); $list->setOrder("ASC"); $list->setOrderKey("name"); $list->load(); $childList = $list->getUsers(); if (is_array($childList)) { foreach ($childList as $user) { if ($user->getId() == $currentUser->getId()) { throw new \Exception("Cannot delete current user"); } if ($user->getId() && $currentUser->getId() && $user->getName() != "system") { $currentList[] = $user; $this->populateChildNodes($user, $currentList); } } } return $currentList; }
/** * This is used for user-permissions, pass a permission type (eg. list, view, save) an you know if the current user is allowed to perform the requested action * * @param string $type * @return boolean */ public function isAllowed($type) { $currentUser = \Pimcore\Tool\Admin::getCurrentUser(); //everything is allowed for admin if ($currentUser->isAdmin()) { return true; } return $this->getDao()->isAllowed($type, $currentUser); }