Ejemplo n.º 1
0
 /**
  * this is a hack for import see: http://www.pimcore.org/issues/browse/PIMCORE-790
  * @param array
  * @return array
  */
 protected function correctClasses($classes)
 {
     // this is the new method with Ext.form.MultiSelect
     /**
      * @extjs6
      * @todo this need to be refactored when extjs3 support is removed
      */
     if (is_string($classes) && !empty($classes) || \Pimcore\Tool\Admin::isExtJS6() && is_array($classes)) {
         if (!\Pimcore\Tool\Admin::isExtJS6()) {
             $classParts = explode(",", $classes);
         } else {
             $classParts = $classes;
         }
         $classes = array();
         foreach ($classParts as $class) {
             if (is_array($class)) {
                 $classes[] = $class;
             } else {
                 if ($class) {
                     $classes[] = array("classes" => $class);
                 }
             }
         }
     }
     // this was the legacy method with Ext.SuperField
     if (is_array($classes) && array_key_exists("classes", $classes)) {
         $classes = array($classes);
     }
     if (!is_array($classes)) {
         $classes = array();
     }
     return $classes;
 }
Ejemplo n.º 2
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $link = Document\Hardlink::getById($this->getParam("id"));
             $this->setValuesToDocument($link);
             $link->setModificationDate(time());
             $link->setUserModification($this->getUser()->getId());
             if ($this->getParam("task") == "unpublish") {
                 $link->setPublished(false);
             }
             if ($this->getParam("task") == "publish") {
                 $link->setPublished(true);
             }
             // only save when publish or unpublish
             if ($this->getParam("task") == "publish" && $link->isAllowed("publish") || $this->getParam("task") == "unpublish" && $link->isAllowed("unpublish")) {
                 $link->save();
                 $this->_helper->json(["success" => true]);
             }
         }
     } catch (\Exception $e) {
         \Logger::log($e);
         if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
             $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
         }
         throw $e;
     }
     $this->_helper->json(false);
 }
Ejemplo n.º 3
0
 public static function getRecordIdForGridRequest($param)
 {
     if (!\Pimcore\Tool\Admin::isExtJS6() && is_numeric($param)) {
         return intval($param);
     } else {
         $param = json_decode($param, true);
         return $param['id'];
     }
 }
Ejemplo n.º 4
0
 public function updateAction()
 {
     $report = CustomReport\Config::getByName($this->getParam("name"));
     $data = \Zend_Json::decode($this->getParam("configuration"));
     if (\Pimcore\Tool\Admin::isExtJS6() && !is_array($data["yAxis"])) {
         $data["yAxis"] = strlen($data["yAxis"]) ? [$data["yAxis"]] : [];
     }
     foreach ($data as $key => $value) {
         $setter = "set" . ucfirst($key);
         if (method_exists($report, $setter)) {
             $report->{$setter}($value);
         }
     }
     $report->save();
     $this->_helper->json(["success" => true]);
 }
Ejemplo n.º 5
0
 public function websiteSettingsAction()
 {
     try {
         if ($this->getParam("data")) {
             $this->checkPermission("website_settings");
             $data = \Zend_Json::decode($this->getParam("data"));
             if (is_array($data)) {
                 foreach ($data as &$value) {
                     $value = trim($value);
                 }
             }
             if ($this->getParam("xaction") == "destroy") {
                 if (\Pimcore\Tool\Admin::isExtJS6()) {
                     $id = $data["id"];
                 } else {
                     $id = $data;
                 }
                 $setting = WebsiteSetting::getById($id);
                 $setting->delete();
                 $this->_helper->json(array("success" => true, "data" => array()));
             } else {
                 if ($this->getParam("xaction") == "update") {
                     // save routes
                     $setting = WebsiteSetting::getById($data["id"]);
                     switch ($setting->getType()) {
                         case "document":
                         case "asset":
                         case "object":
                             if (isset($data["data"])) {
                                 $path = $data["data"];
                                 $element = Element\Service::getElementByPath($setting->getType(), $path);
                                 $data["data"] = $element ? $element->getId() : null;
                             }
                             break;
                     }
                     $setting->setValues($data);
                     $setting->save();
                     $data = $this->getWebsiteSettingForEditMode($setting);
                     $this->_helper->json(array("data" => $data, "success" => true));
                 } else {
                     if ($this->getParam("xaction") == "create") {
                         unset($data["id"]);
                         // save route
                         $setting = new WebsiteSetting();
                         $setting->setValues($data);
                         $setting->save();
                         $this->_helper->json(array("data" => $setting, "success" => true));
                     }
                 }
             }
         } else {
             // get list of routes
             $list = new WebsiteSetting\Listing();
             $list->setLimit($this->getParam("limit"));
             $list->setOffset($this->getParam("start"));
             $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
             if ($sortingSettings['orderKey']) {
                 $list->setOrderKey($sortingSettings['orderKey']);
                 $list->setOrder($sortingSettings['order']);
             } else {
                 $list->setOrderKey("name");
                 $list->setOrder("asc");
             }
             if ($this->getParam("filter")) {
                 $list->setCondition("`name` LIKE " . $list->quote("%" . $this->getParam("filter") . "%"));
             }
             $totalCount = $list->getTotalCount();
             $list = $list->load();
             $settings = array();
             foreach ($list as $item) {
                 $resultItem = $this->getWebsiteSettingForEditMode($item);
                 $settings[] = $resultItem;
             }
             $this->_helper->json(array("data" => $settings, "success" => true, "total" => $totalCount));
         }
     } catch (\Exception $e) {
         throw $e;
         $this->_helper->json(false);
     }
     $this->_helper->json(false);
 }
 public function propertiesAction()
 {
     if ($this->getParam("data")) {
         $dataParam = $this->getParam("data");
         $data = \Zend_Json::decode($dataParam);
         $id = $data["id"];
         $config = Classificationstore\KeyConfig::getById($id);
         foreach ($data as $key => $value) {
             if ($key != "id") {
                 $setter = "set" . $key;
                 if (method_exists($config, $setter)) {
                     $config->{$setter}($value);
                 }
             }
         }
         $config->save();
         $item = $this->getConfigItem($config);
         $this->_helper->json(array("success" => true, "data" => $item));
     } else {
         $start = 0;
         $limit = 15;
         $orderKey = "name";
         $order = "ASC";
         if ($this->getParam("dir")) {
             $order = $this->getParam("dir");
         }
         $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
         if ($sortingSettings['orderKey'] && $sortingSettings['order']) {
             $orderKey = $sortingSettings['orderKey'];
             $order = $sortingSettings['order'];
         }
         if ($this->getParam("overrideSort") == "true") {
             $orderKey = "id";
             $order = "DESC";
         }
         if ($this->getParam("limit")) {
             $limit = $this->getParam("limit");
         }
         if ($this->getParam("start")) {
             $start = $this->getParam("start");
         }
         $list = new Classificationstore\KeyConfig\Listing();
         if ($limit > 0) {
             $list->setLimit($limit);
         }
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $condition = "";
         $db = \Pimcore\Db::get();
         $searchfilter = $this->getParam("searchfilter");
         if ($searchfilter) {
             $condition = "(name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR description LIKE " . $db->quote("%" . $searchfilter . "%") . ")";
         }
         if ($this->getParam("filter")) {
             $filterString = $this->getParam("filter");
             $filters = json_decode($filterString);
             $count = 0;
             foreach ($filters as $f) {
                 if ($count > 0) {
                     $condition .= " AND ";
                 }
                 $count++;
                 if (\Pimcore\Tool\Admin::isExtJS6()) {
                     $condition .= $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
                 } else {
                     $condition .= $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
                 }
             }
         }
         $list->setCondition($condition);
         if ($this->getParam("groupIds") || $this->getParam("keyIds")) {
             $db = Db::get();
             if ($this->getParam("groupIds")) {
                 $ids = \Zend_Json::decode($this->getParam("groupIds"));
                 $col = "group";
             } else {
                 $ids = \Zend_Json::decode($this->getParam("keyIds"));
                 $col = "id";
             }
             $condition = $db->getQuoteIdentifierSymbol() . $col . $db->getQuoteIdentifierSymbol() . " IN (";
             $count = 0;
             foreach ($ids as $theId) {
                 if ($count > 0) {
                     $condition .= ",";
                 }
                 $condition .= $theId;
                 $count++;
             }
             $condition .= ")";
             $list->setCondition($condition);
         }
         $list->load();
         $configList = $list->getList();
         $rootElement = array();
         $data = array();
         foreach ($configList as $config) {
             $item = $this->getConfigItem($config);
             $data[] = $item;
         }
         $rootElement["data"] = $data;
         $rootElement["success"] = true;
         $rootElement["total"] = $list->getTotalCount();
         return $this->_helper->json($rootElement);
     }
 }
Ejemplo n.º 7
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $page = Document\Page::getById($this->getParam("id"));
             // check if there's a document in session which should be used as data-source
             // see also self::clearEditableDataAction() | this is necessary to reset all fields and to get rid of
             // outdated and unused data elements in this document (eg. entries of area-blocks)
             $pageSession = Session::useSession(function ($session) use($page) {
                 if (isset($session->{"document_" . $page->getId()}) && isset($session->{"document_" . $page->getId() . "_useForSave"})) {
                     if ($session->{"document_" . $page->getId() . "_useForSave"}) {
                         // only use the page from the session once
                         unset($session->{"document_" . $page->getId() . "_useForSave"});
                         return $session->{"document_" . $page->getId()};
                     }
                 }
                 return null;
             }, "pimcore_documents");
             if ($pageSession) {
                 $page = $pageSession;
             } else {
                 $page = $this->getLatestVersion($page);
             }
             $page->setUserModification($this->getUser()->getId());
             if ($this->getParam("task") == "unpublish") {
                 $page->setPublished(false);
             }
             if ($this->getParam("task") == "publish") {
                 $page->setPublished(true);
             }
             $settings = [];
             if ($this->getParam("settings")) {
                 $settings = \Zend_Json::decode($this->getParam("settings"));
             }
             // check for redirects
             if ($this->getUser()->isAllowed("redirects") && $this->getParam("settings")) {
                 if (is_array($settings)) {
                     $redirectList = new Redirect\Listing();
                     $redirectList->setCondition("target = ?", $page->getId());
                     $existingRedirects = $redirectList->load();
                     $existingRedirectIds = [];
                     foreach ($existingRedirects as $existingRedirect) {
                         $existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId();
                     }
                     for ($i = 1; $i < 100; $i++) {
                         if (array_key_exists("redirect_url_" . $i, $settings)) {
                             // check for existing
                             if ($settings["redirect_id_" . $i]) {
                                 $redirect = Redirect::getById($settings["redirect_id_" . $i]);
                                 unset($existingRedirectIds[$redirect->getId()]);
                             } else {
                                 // create new one
                                 $redirect = new Redirect();
                             }
                             $redirect->setSource($settings["redirect_url_" . $i]);
                             $redirect->setTarget($page->getId());
                             $redirect->setStatusCode(301);
                             $redirect->save();
                         }
                     }
                     // remove existing redirects which were delete
                     foreach ($existingRedirectIds as $existingRedirectId) {
                         $redirect = Redirect::getById($existingRedirectId);
                         $redirect->delete();
                     }
                 }
             }
             // check if settings exist, before saving meta data
             if ($this->getParam("settings") && is_array($settings)) {
                 $metaData = [];
                 for ($i = 1; $i < 30; $i++) {
                     if (array_key_exists("metadata_" . $i, $settings)) {
                         $metaData[] = $settings["metadata_" . $i];
                     }
                 }
                 $page->setMetaData($metaData);
             }
             // only save when publish or unpublish
             if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
                 $this->setValuesToDocument($page);
                 try {
                     $page->save();
                     $this->saveToSession($page);
                     $this->_helper->json(["success" => true]);
                 } catch (\Exception $e) {
                     if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                         throw $e;
                     }
                     Logger::err($e);
                     $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                 }
             } else {
                 if ($page->isAllowed("save")) {
                     $this->setValuesToDocument($page);
                     try {
                         $page->saveVersion();
                         $this->saveToSession($page);
                         $this->_helper->json(["success" => true]);
                     } catch (\Exception $e) {
                         Logger::err($e);
                         $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         Logger::log($e);
         if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
             $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
         }
         throw $e;
     }
     $this->_helper->json(false);
 }
Ejemplo n.º 8
0
 public function saveAction()
 {
     try {
         $success = false;
         if ($this->getParam("id")) {
             $asset = Asset::getById($this->getParam("id"));
             if ($asset->isAllowed("publish")) {
                 // metadata
                 if ($this->getParam("metadata")) {
                     $metadata = \Zend_Json::decode($this->getParam("metadata"));
                     $metadata = Asset\Service::minimizeMetadata($metadata);
                     $asset->setMetadata($metadata);
                 }
                 // properties
                 if ($this->getParam("properties")) {
                     $properties = [];
                     $propertiesData = \Zend_Json::decode($this->getParam("properties"));
                     if (is_array($propertiesData)) {
                         foreach ($propertiesData as $propertyName => $propertyData) {
                             $value = $propertyData["data"];
                             try {
                                 $property = new Model\Property();
                                 $property->setType($propertyData["type"]);
                                 $property->setName($propertyName);
                                 $property->setCtype("asset");
                                 $property->setDataFromEditmode($value);
                                 $property->setInheritable($propertyData["inheritable"]);
                                 $properties[$propertyName] = $property;
                             } catch (\Exception $e) {
                                 Logger::err("Can't add " . $propertyName . " to asset " . $asset->getRealFullPath());
                             }
                         }
                         $asset->setProperties($properties);
                     }
                 }
                 // scheduled tasks
                 if ($this->getParam("scheduler")) {
                     $tasks = [];
                     $tasksData = \Zend_Json::decode($this->getParam("scheduler"));
                     if (!empty($tasksData)) {
                         foreach ($tasksData as $taskData) {
                             $taskData["date"] = strtotime($taskData["date"] . " " . $taskData["time"]);
                             $task = new Model\Schedule\Task($taskData);
                             $tasks[] = $task;
                         }
                     }
                     $asset->setScheduledTasks($tasks);
                 }
                 if ($this->hasParam("data")) {
                     $asset->setData($this->getParam("data"));
                 }
                 $asset->setUserModification($this->getUser()->getId());
                 try {
                     $asset->save();
                     $asset->getData();
                     $success = true;
                 } catch (\Exception $e) {
                     if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                         throw $e;
                     }
                     $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                 }
             } else {
                 Logger::debug("prevented save asset because of missing permissions ");
             }
             $this->_helper->json(["success" => $success]);
         }
         $this->_helper->json(false);
     } catch (\Exception $e) {
         Logger::log($e);
         if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
             $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
         }
         throw $e;
     }
 }
Ejemplo n.º 9
0
 public function indexAction()
 {
     // clear open edit locks for this session (in the case of a reload, ...)
     \Pimcore\Model\Element\Editlock::clearSession(session_id());
     // check maintenance
     $maintenance_enabled = false;
     $manager = Model\Schedule\Manager\Factory::getManager("maintenance.pid");
     $lastExecution = $manager->getLastExecution();
     if ($lastExecution) {
         if (time() - $lastExecution < 610) {
             // maintenance script should run at least every 10 minutes + a little tolerance
             $maintenance_enabled = true;
         }
     }
     $this->view->maintenance_enabled = \Zend_Json::encode($maintenance_enabled);
     // configuration
     $sysConfig = Config::getSystemConfig();
     $this->view->config = $sysConfig;
     //mail settings
     $mailIncomplete = false;
     if ($sysConfig->email) {
         if (!$sysConfig->email->debug->emailaddresses) {
             $mailIncomplete = true;
         }
         if (!$sysConfig->email->sender->email) {
             $mailIncomplete = true;
         }
         if ($sysConfig->email->method == "smtp" && !$sysConfig->email->smtp->host) {
             $mailIncomplete = true;
         }
     }
     $this->view->mail_settings_complete = \Zend_Json::encode(!$mailIncomplete);
     // report configuration
     $this->view->report_config = Config::getReportConfig();
     $cvData = [];
     // still needed when publishing objects
     $cvConfig = Tool::getCustomViewConfig();
     if ($cvConfig) {
         foreach ($cvConfig as $node) {
             $tmpData = $node;
             // backwards compatibility
             $treeType = $tmpData["treetype"] ? $tmpData["treetype"] : "object";
             $rootNode = Model\Element\Service::getElementByPath($treeType, $tmpData["rootfolder"]);
             if ($rootNode) {
                 $tmpData["rootId"] = $rootNode->getId();
                 $tmpData["allowedClasses"] = $tmpData["classes"] ? explode(",", $tmpData["classes"]) : null;
                 $tmpData["showroot"] = (bool) $tmpData["showroot"];
                 // Check if a user has privileges to that node
                 if ($rootNode->isAllowed("list")) {
                     $cvData[] = $tmpData;
                 }
             }
         }
     }
     $this->view->customview_config = $cvData;
     // upload limit
     $max_upload = filesize2bytes(ini_get("upload_max_filesize") . "B");
     $max_post = filesize2bytes(ini_get("post_max_size") . "B");
     $upload_mb = min($max_upload, $max_post);
     $this->view->upload_max_filesize = $upload_mb;
     // session lifetime (gc)
     $session_gc_maxlifetime = ini_get("session.gc_maxlifetime");
     if (empty($session_gc_maxlifetime)) {
         $session_gc_maxlifetime = 120;
     }
     $this->view->session_gc_maxlifetime = $session_gc_maxlifetime;
     // csrf token
     $user = $this->getUser();
     $this->view->csrfToken = Tool\Session::useSession(function ($adminSession) use($user) {
         if (!isset($adminSession->csrfToken) && !$adminSession->csrfToken) {
             $adminSession->csrfToken = sha1(microtime() . $user->getName() . uniqid());
         }
         return $adminSession->csrfToken;
     });
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         $this->forward("index6");
     }
 }
Ejemplo n.º 10
0
 /**
  *
  * @param string $filterJson
  * @param ClassDefinition $class
  * @return string
  */
 public static function getFilterCondition($filterJson, $class)
 {
     $systemFields = array("o_path", "o_key", "o_id", "o_published", "o_creationDate", "o_modificationDate", "o_fullpath");
     // create filter condition
     $conditionPartsFilters = array();
     if ($filterJson) {
         $db = \Pimcore\Db::get();
         $filters = \Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             /**
              * @extjs
              */
             $filterField = $filter["field"];
             $filterOperator = $filter["comparison"];
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $filterField = $filter["property"];
                 $filterOperator = $filter["operator"];
             }
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
             } else {
                 if ($filter["type"] == "numeric") {
                     if ($filterOperator == "lt") {
                         $operator = "<";
                     } else {
                         if ($filterOperator == "gt") {
                             $operator = ">";
                         } else {
                             if ($filterOperator == "eq") {
                                 $operator = "=";
                             }
                         }
                     }
                 } else {
                     if ($filter["type"] == "date") {
                         if ($filterOperator == "lt") {
                             $operator = "<";
                         } else {
                             if ($filterOperator == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filterOperator == "eq") {
                                     $operator = "=";
                                 }
                             }
                         }
                         $filter["value"] = strtotime($filter["value"]);
                     } else {
                         if ($filter["type"] == "list") {
                             $operator = "=";
                         } else {
                             if ($filter["type"] == "boolean") {
                                 $operator = "=";
                                 $filter["value"] = (int) $filter["value"];
                             }
                         }
                     }
                 }
             }
             $field = $class->getFieldDefinition($filterField);
             $brickField = null;
             $brickType = null;
             if (!$field) {
                 // if the definition doesn't exist check for a localized field
                 $localized = $class->getFieldDefinition("localizedfields");
                 if ($localized instanceof ClassDefinition\Data\Localizedfields) {
                     $field = $localized->getFieldDefinition($filterField);
                 }
                 //if the definition doesn't exist check for object brick
                 $keyParts = explode("~", $filterField);
                 if (substr($filterField, 0, 1) == "~") {
                     // not needed for now
                     //                            $type = $keyParts[1];
                     //                            $field = $keyParts[2];
                     //                            $keyid = $keyParts[3];
                 } else {
                     if (count($keyParts) > 1) {
                         $brickType = $keyParts[0];
                         $brickKey = $keyParts[1];
                         $key = self::getFieldForBrickType($class, $brickType);
                         $field = $class->getFieldDefinition($key);
                         $brickClass = Objectbrick\Definition::getByKey($brickType);
                         $brickField = $brickClass->getFieldDefinition($brickKey);
                     }
                 }
             }
             if ($field instanceof ClassDefinition\Data\Objectbricks) {
                 // custom field
                 $db = \Pimcore\Db::get();
                 if (is_array($filter["value"])) {
                     $fieldConditions = array();
                     foreach ($filter["value"] as $filterValue) {
                         $fieldConditions[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filterValue, $operator);
                     }
                     $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                 } else {
                     $conditionPartsFilters[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filter["value"], $operator);
                 }
             } else {
                 if ($field instanceof ClassDefinition\Data) {
                     // custom field
                     if (is_array($filter["value"])) {
                         $fieldConditions = array();
                         foreach ($filter["value"] as $filterValue) {
                             $fieldConditions[] = $field->getFilterCondition($filterValue, $operator);
                         }
                         $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                     } else {
                         $conditionPartsFilters[] = $field->getFilterCondition($filter["value"], $operator);
                     }
                 } else {
                     if (in_array("o_" . $filterField, $systemFields)) {
                         // system field
                         if ($filterField == "fullpath") {
                             $conditionPartsFilters[] = "concat(o_path, o_key) " . $operator . " " . $db->quote("%" . $filter["value"] . "%");
                         } else {
                             $conditionPartsFilters[] = "`o_" . $filterField . "` " . $operator . " " . $db->quote($filter["value"]);
                         }
                     }
                 }
             }
         }
     }
     $conditionFilters = "1 = 1";
     if (count($conditionPartsFilters) > 0) {
         $conditionFilters = "(" . implode(" AND ", $conditionPartsFilters) . ")";
     }
     \Logger::log("ObjectController filter condition:" . $conditionFilters);
     return $conditionFilters;
 }
Ejemplo n.º 11
0
    /**
     * @param \Zend_Controller_Request_Abstract $request
     */
    public function postDispatch(\Zend_Controller_Request_Abstract $request)
    {
        $conf = Config::getSystemConfig();
        // add scripts to editmode
        if (\Pimcore\Tool\Admin::isExtJS6()) {
            $editmodeLibraries = array("/pimcore/static6/js/pimcore/namespace.js", "/pimcore/static6/js/lib/prototype-light.js", "/pimcore/static6/js/lib/jquery.min.js", "/pimcore/static6/js/lib/ext/ext-all.js", "/pimcore/static6/js/lib/ckeditor/ckeditor.js");
            $editmodeScripts = array("/pimcore/static6/js/pimcore/functions.js", "/pimcore/static6/js/pimcore/element/tag/imagehotspotmarkereditor.js", "/pimcore/static6/js/pimcore/element/tag/imagecropper.js", "/pimcore/static6/js/pimcore/document/edit/helper.js", "/pimcore/static6/js/pimcore/document/edit/dnd.js", "/pimcore/static6/js/pimcore/document/tag.js", "/pimcore/static6/js/pimcore/document/tags/block.js", "/pimcore/static6/js/pimcore/document/tags/date.js", "/pimcore/static6/js/pimcore/document/tags/href.js", "/pimcore/static6/js/pimcore/document/tags/multihref.js", "/pimcore/static6/js/pimcore/document/tags/checkbox.js", "/pimcore/static6/js/pimcore/document/tags/image.js", "/pimcore/static6/js/pimcore/document/tags/input.js", "/pimcore/static6/js/pimcore/document/tags/link.js", "/pimcore/static6/js/pimcore/document/tags/select.js", "/pimcore/static6/js/pimcore/document/tags/snippet.js", "/pimcore/static6/js/pimcore/document/tags/textarea.js", "/pimcore/static6/js/pimcore/document/tags/numeric.js", "/pimcore/static6/js/pimcore/document/tags/wysiwyg.js", "/pimcore/static6/js/pimcore/document/tags/renderlet.js", "/pimcore/static6/js/pimcore/document/tags/table.js", "/pimcore/static6/js/pimcore/document/tags/video.js", "/pimcore/static6/js/pimcore/document/tags/multiselect.js", "/pimcore/static6/js/pimcore/document/tags/areablock.js", "/pimcore/static6/js/pimcore/document/tags/area.js", "/pimcore/static6/js/pimcore/document/tags/pdf.js", "/pimcore/static6/js/pimcore/document/edit/helper.js");
            $editmodeStylesheets = array("/pimcore/static6/css/icons.css", "/pimcore/static6/css/editmode.css?_dc=" . time());
        } else {
            $editmodeLibraries = array("/pimcore/static/js/pimcore/namespace.js", "/pimcore/static/js/lib/prototype-light.js", "/pimcore/static/js/lib/jquery.min.js", "/pimcore/static/js/lib/ext/adapter/jquery/ext-jquery-adapter-debug.js", "/pimcore/static/js/lib/ext/ext-all-debug.js", "/pimcore/static/js/lib/ext-plugins/ux/Spinner.js", "/pimcore/static/js/lib/ext-plugins/ux/SpinnerField.js", "/pimcore/static/js/lib/ext-plugins/ux/MultiSelect.js", "/pimcore/static/js/lib/ext-plugins/GridRowOrder/roworder.js", "/pimcore/static/js/lib/ckeditor/ckeditor.js", "/pimcore/static/js/pimcore/libfixes.js");
            $editmodeScripts = array("/pimcore/static/js/pimcore/functions.js", "/pimcore/static/js/pimcore/element/tag/imagehotspotmarkereditor.js", "/pimcore/static/js/pimcore/element/tag/imagecropper.js", "/pimcore/static/js/pimcore/document/edit/helper.js", "/pimcore/static/js/pimcore/document/edit/dnd.js", "/pimcore/static/js/pimcore/document/tag.js", "/pimcore/static/js/pimcore/document/tags/block.js", "/pimcore/static/js/pimcore/document/tags/date.js", "/pimcore/static/js/pimcore/document/tags/href.js", "/pimcore/static/js/pimcore/document/tags/multihref.js", "/pimcore/static/js/pimcore/document/tags/checkbox.js", "/pimcore/static/js/pimcore/document/tags/image.js", "/pimcore/static/js/pimcore/document/tags/input.js", "/pimcore/static/js/pimcore/document/tags/link.js", "/pimcore/static/js/pimcore/document/tags/select.js", "/pimcore/static/js/pimcore/document/tags/snippet.js", "/pimcore/static/js/pimcore/document/tags/textarea.js", "/pimcore/static/js/pimcore/document/tags/numeric.js", "/pimcore/static/js/pimcore/document/tags/wysiwyg.js", "/pimcore/static/js/pimcore/document/tags/renderlet.js", "/pimcore/static/js/pimcore/document/tags/table.js", "/pimcore/static/js/pimcore/document/tags/video.js", "/pimcore/static/js/pimcore/document/tags/multiselect.js", "/pimcore/static/js/pimcore/document/tags/areablock.js", "/pimcore/static/js/pimcore/document/tags/area.js", "/pimcore/static/js/pimcore/document/tags/pdf.js", "/pimcore/static/js/pimcore/document/edit/helper.js");
            $editmodeStylesheets = array("/pimcore/static/css/icons.css", "/pimcore/static/css/editmode.css?asd=" . time());
        }
        //add plugin editmode JS and CSS
        try {
            $pluginConfigs = ExtensionManager::getPluginConfigs();
            $jsPaths = array();
            $cssPaths = array();
            if (!empty($pluginConfigs)) {
                //registering plugins
                foreach ($pluginConfigs as $p) {
                    $pluginJsPaths = array();
                    if (array_key_exists("pluginDocumentEditmodeJsPaths", $p['plugin']) && is_array($p['plugin']['pluginDocumentEditmodeJsPaths']) && isset($p['plugin']['pluginDocumentEditmodeJsPaths']['path'])) {
                        if (is_array($p['plugin']['pluginDocumentEditmodeJsPaths']['path'])) {
                            $pluginJsPaths = $p['plugin']['pluginDocumentEditmodeJsPaths']['path'];
                        } else {
                            if ($p['plugin']['pluginDocumentEditmodeJsPaths']['path'] != null) {
                                $pluginJsPaths[] = $p['plugin']['pluginDocumentEditmodeJsPaths']['path'];
                            }
                        }
                    }
                    //manipulate path for frontend
                    if (is_array($pluginJsPaths) and count($pluginJsPaths) > 0) {
                        for ($i = 0; $i < count($pluginJsPaths); $i++) {
                            if (is_file(PIMCORE_PLUGINS_PATH . $pluginJsPaths[$i])) {
                                $jsPaths[] = "/plugins" . $pluginJsPaths[$i];
                            }
                        }
                    }
                    $pluginCssPaths = array();
                    if (array_key_exists("pluginDocumentEditmodeCssPaths", $p['plugin']) && is_array($p['plugin']['pluginDocumentEditmodeCssPaths']) && isset($p['plugin']['pluginDocumentEditmodeCssPaths']['path'])) {
                        if (is_array($p['plugin']['pluginDocumentEditmodeCssPaths']['path'])) {
                            $pluginCssPaths = $p['plugin']['pluginDocumentEditmodeCssPaths']['path'];
                        } else {
                            if ($p['plugin']['pluginDocumentEditmodeCssPaths']['path'] != null) {
                                $pluginCssPaths[] = $p['plugin']['pluginDocumentEditmodeCssPaths']['path'];
                            }
                        }
                    }
                    //manipulate path for frontend
                    if (is_array($pluginCssPaths) and count($pluginCssPaths) > 0) {
                        for ($i = 0; $i < count($pluginCssPaths); $i++) {
                            if (is_file(PIMCORE_PLUGINS_PATH . $pluginCssPaths[$i])) {
                                $cssPaths[] = "/plugins" . $pluginCssPaths[$i];
                            }
                        }
                    }
                }
            }
            $editmodeScripts = array_merge($editmodeScripts, $jsPaths);
            $editmodeStylesheets = array_merge($editmodeStylesheets, $cssPaths);
        } catch (\Exception $e) {
            \Logger::alert("there is a problem with the plugin configuration");
            \Logger::alert($e);
        }
        $editmodeHeadHtml = "\n\n\n<!-- pimcore editmode -->\n";
        // include stylesheets
        foreach ($editmodeStylesheets as $sheet) {
            $editmodeHeadHtml .= '<link rel="stylesheet" type="text/css" href="' . $sheet . '?_dc=' . Version::$revision . '" />';
            $editmodeHeadHtml .= "\n";
        }
        $editmodeHeadHtml .= "\n\n";
        $editmodeHeadHtml .= '<script type="text/javascript">var jQueryPreviouslyLoaded = (typeof jQuery == "undefined") ? false : true;</script>' . "\n";
        // include script libraries
        foreach ($editmodeLibraries as $script) {
            $editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Version::$revision . '"></script>';
            $editmodeHeadHtml .= "\n";
        }
        // combine the pimcore scripts in non-devmode
        if ($conf->general->devmode) {
            foreach ($editmodeScripts as $script) {
                $editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Version::$revision . '"></script>';
                $editmodeHeadHtml .= "\n";
            }
        } else {
            $scriptContents = "";
            foreach ($editmodeScripts as $scriptUrl) {
                $scriptContents .= file_get_contents(PIMCORE_DOCUMENT_ROOT . $scriptUrl) . "\n\n\n";
            }
            $editmodeHeadHtml .= '<script type="text/javascript" src="' . \Pimcore\Tool\Admin::getMinimizedScriptPath($scriptContents) . '?_dc=' . Version::$revision . '"></script>' . "\n";
        }
        $user = \Pimcore\Tool\Authentication::authenticateSession();
        $lang = $user->getLanguage();
        $editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-system/language/' . $lang . '/?_dc=' . Version::$revision . '"></script>' . "\n";
        $editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-admin/language/' . $lang . '/?_dc=' . Version::$revision . '"></script>' . "\n";
        $editmodeHeadHtml .= "\n\n";
        // set var for editable configurations which is filled by Document\Tag::admin()
        $editmodeHeadHtml .= '<script type="text/javascript">
            var editableConfigurations = new Array();
            var pimcore_document_id = ' . $request->getParam("document")->getId() . ';

            if(jQueryPreviouslyLoaded) {
                jQuery.noConflict( true );
            }
        </script>';
        $editmodeHeadHtml .= "\n\n<!-- /pimcore editmode -->\n\n\n";
        // add scripts in html header for pages in editmode
        if ($this->controller->editmode && Document\Service::isValidType($this->controller->document->getType())) {
            //ckogler
            include_once "simple_html_dom.php";
            $body = $this->getResponse()->getBody();
            $html = str_get_html($body);
            if ($html) {
                $htmlElement = $html->find("html", 0);
                $head = $html->find("head", 0);
                $bodyElement = $html->find("body", 0);
                // if there's no head and no body, create a wrapper including these elements
                // add html headers for snippets in editmode, so there is no problem with javascript
                if (!$head && !$bodyElement && !$htmlElement) {
                    $body = "<!DOCTYPE html>\n<html>\n<head></head><body>" . $body . "</body></html>";
                    $html = str_get_html($body);
                    // get them again with the updated html markup
                    $htmlElement = $html->find("html", 0);
                    $head = $html->find("head", 0);
                    $bodyElement = $html->find("body", 0);
                }
                if ($head && $bodyElement && $htmlElement) {
                    $head->innertext = $head->innertext . "\n\n" . $editmodeHeadHtml;
                    $bodyElement->onunload = "pimcoreOnUnload();";
                    if (\Pimcore\Tool\Admin::isExtJS6()) {
                        $bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static6/js/pimcore/document/edit/startup.js?_dc=' . Version::$revision . '"></script>' . "\n\n";
                    } else {
                        $bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static/js/pimcore/document/edit/startup.js?_dc=' . Version::$revision . '"></script>' . "\n\n";
                    }
                    $body = $html->save();
                    $this->getResponse()->setBody($body);
                } else {
                    $this->getResponse()->setBody('<div style="font-size:30px; font-family: Arial; font-weight:bold; color:red; text-align: center; margin: 40px 0">You have to define a &lt;html&gt;, &lt;head&gt;, &lt;body&gt;<br />HTML-tag in your view/layout markup!</div>');
                }
                $html->clear();
                unset($html);
            }
        }
        // IE compatibility
        //$this->getResponse()->setHeader("X-UA-Compatible", "IE=8; IE=9", true);
    }
Ejemplo n.º 12
0
 /**
  * @param array $docTypes
  */
 public function setDocTypes($docTypes)
 {
     if (!\Pimcore\Tool\Admin::isExtJS6()) {
         if (strlen($docTypes)) {
             $docTypes = explode(",", $docTypes);
         }
     }
     if (empty($docTypes)) {
         $docTypes = array();
     }
     $this->docTypes = $docTypes;
 }
Ejemplo n.º 13
0
 /**
  *
  */
 public static function initPlugins()
 {
     // add plugin include paths
     $autoloader = \Zend_Loader_Autoloader::getInstance();
     try {
         $pluginConfigs = ExtensionManager::getPluginConfigs();
         if (!empty($pluginConfigs)) {
             $includePaths = array(get_include_path());
             //adding plugin include paths and namespaces
             if (count($pluginConfigs) > 0) {
                 foreach ($pluginConfigs as $p) {
                     if (!ExtensionManager::isEnabled("plugin", $p["plugin"]["pluginName"])) {
                         continue;
                     }
                     if (is_array($p['plugin']['pluginIncludePaths']['path'])) {
                         foreach ($p['plugin']['pluginIncludePaths']['path'] as $path) {
                             $includePaths[] = PIMCORE_PLUGINS_PATH . $path;
                         }
                     } else {
                         if ($p['plugin']['pluginIncludePaths']['path'] != null) {
                             $includePaths[] = PIMCORE_PLUGINS_PATH . $p['plugin']['pluginIncludePaths']['path'];
                         }
                     }
                     if (is_array($p['plugin']['pluginNamespaces']['namespace'])) {
                         foreach ($p['plugin']['pluginNamespaces']['namespace'] as $namespace) {
                             $autoloader->registerNamespace($namespace);
                         }
                     } else {
                         if ($p['plugin']['pluginNamespaces']['namespace'] != null) {
                             $autoloader->registerNamespace($p['plugin']['pluginNamespaces']['namespace']);
                         }
                     }
                 }
             }
             set_include_path(implode(PATH_SEPARATOR, $includePaths));
             $broker = \Pimcore\API\Plugin\Broker::getInstance();
             //registering plugins
             foreach ($pluginConfigs as $p) {
                 if (!ExtensionManager::isEnabled("plugin", $p["plugin"]["pluginName"])) {
                     continue;
                 }
                 $jsPaths = array();
                 $isExtJs6 = \Pimcore\Tool\Admin::isExtJS6();
                 if ($isExtJs6 && is_array($p['plugin']['pluginJsPaths-extjs6']) && isset($p['plugin']['pluginJsPaths-extjs6']['path']) && is_array($p['plugin']['pluginJsPaths-extjs6']['path'])) {
                     $jsPaths = $p['plugin']['pluginJsPaths-extjs6']['path'];
                 } else {
                     if ($isExtJs6 && is_array($p['plugin']['pluginJsPaths-extjs6']) && $p['plugin']['pluginJsPaths-extjs6']['path'] != null) {
                         $jsPaths[0] = $p['plugin']['pluginJsPaths-extjs6']['path'];
                     } else {
                         if (is_array($p['plugin']['pluginJsPaths']) && isset($p['plugin']['pluginJsPaths']['path']) && is_array($p['plugin']['pluginJsPaths']['path'])) {
                             $jsPaths = $p['plugin']['pluginJsPaths']['path'];
                         } else {
                             if (is_array($p['plugin']['pluginJsPaths']) && $p['plugin']['pluginJsPaths']['path'] != null) {
                                 $jsPaths[0] = $p['plugin']['pluginJsPaths']['path'];
                             }
                         }
                     }
                 }
                 //manipulate path for frontend
                 if (is_array($jsPaths) and count($jsPaths) > 0) {
                     for ($i = 0; $i < count($jsPaths); $i++) {
                         if (is_file(PIMCORE_PLUGINS_PATH . $jsPaths[$i])) {
                             $jsPaths[$i] = "/plugins" . $jsPaths[$i];
                         }
                     }
                 }
                 $cssPaths = array();
                 if ($isExtJs6 && is_array($p['plugin']['pluginCssPaths-extjs6']) && isset($p['plugin']['pluginCssPaths-extjs6']['path']) && is_array($p['plugin']['pluginCssPaths-extjs6']['path'])) {
                     $cssPaths = $p['plugin']['pluginCssPaths-extjs6']['path'];
                 } else {
                     if ($isExtJs6 && is_array($p['plugin']['pluginCssPaths-extjs6']) && $p['plugin']['pluginCssPaths-extjs6']['path'] != null) {
                         $cssPaths[0] = $p['plugin']['pluginCssPaths-extjs6']['path'];
                     } else {
                         if (is_array($p['plugin']['pluginCssPaths']) && isset($p['plugin']['pluginCssPaths']['path']) && is_array($p['plugin']['pluginCssPaths']['path'])) {
                             $cssPaths = $p['plugin']['pluginCssPaths']['path'];
                         } else {
                             if (is_array($p['plugin']['pluginCssPaths']) && $p['plugin']['pluginCssPaths']['path'] != null) {
                                 $cssPaths[0] = $p['plugin']['pluginCssPaths']['path'];
                             }
                         }
                     }
                 }
                 //manipulate path for frontend
                 if (is_array($cssPaths) and count($cssPaths) > 0) {
                     for ($i = 0; $i < count($cssPaths); $i++) {
                         if (is_file(PIMCORE_PLUGINS_PATH . $cssPaths[$i])) {
                             $cssPaths[$i] = "/plugins" . $cssPaths[$i];
                         }
                     }
                 }
                 try {
                     $className = $p['plugin']['pluginClassName'];
                     if (!empty($className) && Tool::classExists($className)) {
                         $plugin = new $className($jsPaths, $cssPaths);
                         if ($plugin instanceof \Pimcore\API\Plugin\AbstractPlugin) {
                             $broker->registerPlugin($plugin);
                         }
                     }
                 } catch (\Exception $e) {
                     \Logger::err("Could not instantiate and register plugin [" . $p['plugin']['pluginClassName'] . "]");
                 }
             }
             \Zend_Registry::set("Pimcore_API_Plugin_Broker", $broker);
         }
     } catch (\Exception $e) {
         \Logger::alert("there is a problem with the plugin configuration");
         \Logger::alert($e);
     }
 }
Ejemplo n.º 14
0
 /**
  * @param $element
  * @return array
  */
 protected function getTreeNodeConfig($element)
 {
     $childDocument = $element;
     $tmpDocument = array("id" => $childDocument->getId(), "text" => $childDocument->getKey(), "type" => $childDocument->getType(), "path" => $childDocument->getFullPath(), "basePath" => $childDocument->getPath(), "locked" => $childDocument->isLocked(), "lockOwner" => $childDocument->getLocked() ? true : false, "published" => $childDocument->isPublished(), "elementType" => "document", "leaf" => true, "permissions" => array("view" => $childDocument->isAllowed("view"), "remove" => $childDocument->isAllowed("delete"), "settings" => $childDocument->isAllowed("settings"), "rename" => $childDocument->isAllowed("rename"), "publish" => $childDocument->isAllowed("publish"), "unpublish" => $childDocument->isAllowed("unpublish")));
     // add icon
     $tmpDocument["iconCls"] = "pimcore_icon_" . $childDocument->getType();
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         $tmpDocument["expandable"] = $childDocument->hasChilds();
         $tmpDocument["loaded"] = !$childDocument->hasChilds();
     }
     // set type specific settings
     if ($childDocument->getType() == "page") {
         $tmpDocument["leaf"] = false;
         $tmpDocument["expanded"] = $childDocument->hasNoChilds();
         $tmpDocument["permissions"]["create"] = $childDocument->isAllowed("create");
         $tmpDocument["iconCls"] = "pimcore_icon_page";
         // test for a site
         try {
             $site = Site::getByRootId($childDocument->getId());
             $tmpDocument["iconCls"] = "pimcore_icon_site";
             unset($site->rootDocument);
             $tmpDocument["site"] = $site;
         } catch (\Exception $e) {
         }
     } elseif ($childDocument->getType() == "folder" || $childDocument->getType() == "link" || $childDocument->getType() == "hardlink") {
         $tmpDocument["leaf"] = false;
         $tmpDocument["expanded"] = $childDocument->hasNoChilds();
         if ($childDocument->hasNoChilds() && $childDocument->getType() == "folder") {
             $tmpDocument["iconCls"] = "pimcore_icon_folder";
         }
         $tmpDocument["permissions"]["create"] = $childDocument->isAllowed("create");
     } elseif (method_exists($childDocument, "getTreeNodeConfig")) {
         $tmp = $childDocument->getTreeNodeConfig();
         $tmpDocument = array_merge($tmpDocument, $tmp);
     }
     $tmpDocument["qtipCfg"] = array("title" => "ID: " . $childDocument->getId(), "text" => "Type: " . $childDocument->getType());
     // PREVIEWS temporary disabled, need's to be optimized some time
     if ($childDocument instanceof Document\Page && Config::getSystemConfig()->documents->generatepreview) {
         $thumbnailFile = PIMCORE_TEMPORARY_DIRECTORY . "/document-page-previews/document-page-screenshot-" . $childDocument->getId() . ".jpg";
         // only if the thumbnail exists and isn't out of time
         if (file_exists($thumbnailFile) && filemtime($thumbnailFile) > $childDocument->getModificationDate() - 20) {
             $thumbnailPath = str_replace(PIMCORE_DOCUMENT_ROOT, "", $thumbnailFile);
             $tmpDocument["thumbnail"] = $thumbnailPath;
         }
     }
     $tmpDocument["cls"] = "";
     if (!$childDocument->isPublished()) {
         $tmpDocument["cls"] .= "pimcore_unpublished ";
     }
     if ($childDocument->isLocked()) {
         $tmpDocument["cls"] .= "pimcore_treenode_locked ";
     }
     if ($childDocument->getLocked()) {
         $tmpDocument["cls"] .= "pimcore_treenode_lockOwner ";
     }
     return $tmpDocument;
 }
Ejemplo n.º 15
0
 public function listAction()
 {
     if ($this->getParam("xaction") == "destroy") {
         $item = Recyclebin\Item::getById(\Pimcore\Admin\Helper\QueryParams::getRecordIdForGridRequest($this->getParam("data")));
         $item->delete();
         $this->_helper->json(array("success" => true, "data" => array()));
     } else {
         $list = new Recyclebin\Item\Listing();
         $list->setLimit($this->getParam("limit"));
         $list->setOffset($this->getParam("start"));
         $list->setOrderKey("date");
         $list->setOrder("DESC");
         $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
         if ($sortingSettings['orderKey']) {
             $list->setOrderKey($sortingSettings['orderKey']);
             $list->setOrder($sortingSettings['order']);
         }
         $conditionFilters = array();
         if ($this->getParam("filterFullText")) {
             $conditionFilters[] = "path LIKE " . $list->quote("%" . $this->getParam("filterFullText") . "%");
         }
         $filters = $this->getParam("filter");
         if ($filters) {
             $filters = \Zend_Json::decode($filters);
             foreach ($filters as $filter) {
                 $operator = "=";
                 $filterField = $filter["field"];
                 $filterOperator = $filter["comparison"];
                 if (\Pimcore\Tool\Admin::isExtJS6()) {
                     $filterField = $filter["property"];
                     $filterOperator = $filter["operator"];
                 }
                 if ($filter["type"] == "string") {
                     $operator = "LIKE";
                 } elseif ($filter["type"] == "numeric") {
                     if ($filterOperator == "lt") {
                         $operator = "<";
                     } elseif ($filterOperator == "gt") {
                         $operator = ">";
                     } elseif ($filterOperator == "eq") {
                         $operator = "=";
                     }
                 } elseif ($filter["type"] == "date") {
                     if ($filterOperator == "lt") {
                         $operator = "<";
                     } elseif ($filterOperator == "gt") {
                         $operator = ">";
                     } elseif ($filterOperator == "eq") {
                         $operator = "=";
                     }
                     $filter["value"] = strtotime($filter["value"]);
                 } elseif ($filter["type"] == "list") {
                     $operator = "=";
                 } elseif ($filter["type"] == "boolean") {
                     $operator = "=";
                     $filter["value"] = (int) $filter["value"];
                 }
                 // system field
                 $value = $filter["value"];
                 if ($operator == "LIKE") {
                     $value = "%" . $value . "%";
                 }
                 $field = "`" . $filterField . "` ";
                 if ($filter["field"] == "fullpath") {
                     $field = "CONCAT(path,filename)";
                 }
                 $conditionFilters[] = $field . $operator . " '" . $value . "' ";
             }
         }
         if (!empty($conditionFilters)) {
             $condition = implode(" AND ", $conditionFilters);
             $list->setCondition($condition);
         }
         $items = $list->load();
         $this->_helper->json(array("data" => $items, "success" => true, "total" => $list->getTotalCount()));
     }
 }
Ejemplo n.º 16
0
 /**
  *
  * Checks if an asset is an allowed relation
  * @param Asset $asset
  * @return boolean
  */
 protected function allowAssetRelation($asset)
 {
     $allowedAssetTypes = $this->getAssetTypes();
     $allowedTypes = [];
     $allowed = true;
     if (!$this->getAssetsAllowed()) {
         $allowed = false;
     } elseif ($this->getAssetsAllowed() and is_array($allowedAssetTypes) and count($allowedAssetTypes) > 0) {
         //check for allowed asset types
         foreach ($allowedAssetTypes as $t) {
             if (is_array($t) && array_key_exists("assetTypes", $t)) {
                 $t = $t["assetTypes"];
             }
             if ($t) {
                 if (Admin::isExtJS6()) {
                     if (is_string($t)) {
                         $allowedTypes[] = $t;
                     } elseif (is_array($t) && count($t) > 0) {
                         if (isset($t["assetTypes"])) {
                             $allowedTypes[] = $t["assetTypes"];
                         } else {
                             $allowedTypes[] = $t;
                         }
                     }
                 } else {
                     if (is_string($t)) {
                         $allowedTypes[] = $t;
                     }
                 }
             }
         }
         if (!in_array($asset->getType(), $allowedTypes)) {
             $allowed = false;
         }
     } else {
         //don't check if no allowed asset types set
     }
     Logger::debug("checked object relation to target asset [" . $asset->getId() . "] in field [" . $this->getName() . "], allowed:" . $allowed);
     return $allowed;
 }
Ejemplo n.º 17
0
 public function saveAction()
 {
     try {
         $object = Object::getById($this->getParam("id"));
         $originalModificationDate = $object->getModificationDate();
         // set the latest available version for editmode
         $object = $this->getLatestVersion($object);
         $object->setUserModification($this->getUser()->getId());
         // data
         if ($this->getParam("data")) {
             $data = \Zend_Json::decode($this->getParam("data"));
             foreach ($data as $key => $value) {
                 $fd = $object->getClass()->getFieldDefinition($key);
                 if ($fd) {
                     if ($fd instanceof Object\ClassDefinition\Data\Localizedfields) {
                         $user = Tool\Admin::getCurrentUser();
                         if (!$user->getAdmin()) {
                             $allowedLanguages = Object\Service::getLanguagePermissions($object, $user, "lEdit");
                             if (!is_null($allowedLanguages)) {
                                 $allowedLanguages = array_keys($allowedLanguages);
                                 $submittedLanguages = array_keys($data[$key]);
                                 foreach ($submittedLanguages as $submittedLanguage) {
                                     if (!in_array($submittedLanguage, $allowedLanguages)) {
                                         unset($value[$submittedLanguage]);
                                     }
                                 }
                             }
                         }
                     }
                     if (method_exists($fd, "isRemoteOwner") and $fd->isRemoteOwner()) {
                         $remoteClass = Object\ClassDefinition::getByName($fd->getOwnerClassName());
                         $relations = $object->getRelationData($fd->getOwnerFieldName(), false, $remoteClass->getId());
                         $toAdd = $this->detectAddedRemoteOwnerRelations($relations, $value);
                         $toDelete = $this->detectDeletedRemoteOwnerRelations($relations, $value);
                         if (count($toAdd) > 0 or count($toDelete) > 0) {
                             $this->processRemoteOwnerRelations($object, $toDelete, $toAdd, $fd->getOwnerFieldName());
                         }
                     } else {
                         $object->setValue($key, $fd->getDataFromEditmode($value, $object));
                     }
                 }
             }
         }
         // general settings
         // @TODO: IS THIS STILL NECESSARY?
         if ($this->getParam("general")) {
             $general = \Zend_Json::decode($this->getParam("general"));
             // do not allow all values to be set, will cause problems (eg. icon)
             if (is_array($general) && count($general) > 0) {
                 foreach ($general as $key => $value) {
                     if (!in_array($key, ["o_id", "o_classId", "o_className", "o_type", "icon", "o_userOwner", "o_userModification"])) {
                         $object->setValue($key, $value);
                     }
                 }
             }
         }
         $object = $this->assignPropertiesFromEditmode($object);
         // scheduled tasks
         if ($this->getParam("scheduler")) {
             $tasks = [];
             $tasksData = \Zend_Json::decode($this->getParam("scheduler"));
             if (!empty($tasksData)) {
                 foreach ($tasksData as $taskData) {
                     $taskData["date"] = strtotime($taskData["date"] . " " . $taskData["time"]);
                     $task = new Model\Schedule\Task($taskData);
                     $tasks[] = $task;
                 }
             }
             $object->setScheduledTasks($tasks);
         }
         if ($this->getParam("task") == "unpublish") {
             $object->setPublished(false);
         }
         if ($this->getParam("task") == "publish") {
             $object->setPublished(true);
         }
         // unpublish and save version is possible without checking mandatory fields
         if ($this->getParam("task") == "unpublish" || $this->getParam("task") == "version") {
             $object->setOmitMandatoryCheck(true);
         }
         if ($this->getParam("task") == "publish" && $object->isAllowed("publish") or $this->getParam("task") == "unpublish" && $object->isAllowed("unpublish")) {
             if ($data) {
                 $this->performFieldcollectionModificationCheck($object, $originalModificationDate, $data);
             }
             $object->save();
             $treeData = $this->getTreeNodeConfig($object);
             $this->_helper->json(["success" => true, "general" => ["o_modificationDate" => $object->getModificationDate()], "treeData" => $treeData]);
         } elseif ($this->getParam("task") == "session") {
             //$object->_fulldump = true; // not working yet, donno why
             Tool\Session::useSession(function ($session) use($object) {
                 $key = "object_" . $object->getId();
                 $session->{$key} = $object;
             }, "pimcore_objects");
             $this->_helper->json(["success" => true]);
         } else {
             if ($object->isAllowed("save")) {
                 $object->saveVersion();
                 $treeData = $this->getTreeNodeConfig($object);
                 $this->_helper->json(["success" => true, "general" => ["o_modificationDate" => $object->getModificationDate()], "treeData" => $treeData]);
             }
         }
     } catch (\Exception $e) {
         Logger::log($e);
         if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
             $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
         }
         throw $e;
     }
 }
Ejemplo n.º 18
0
 protected function getGridFilterCondition()
 {
     $db = \Pimcore\Db::get();
     $conditionFilters = [];
     $filterJson = $this->getParam("filter");
     if ($filterJson) {
         $isExtJs6 = \Pimcore\Tool\Admin::isExtJS6();
         if ($isExtJs6) {
             $propertyField = "property";
             $operatorField = "operator";
         } else {
             $propertyField = "field";
             $operatorField = "comparison";
         }
         $filters = \Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             $field = null;
             $value = null;
             $fieldname = $filter[$propertyField];
             if ($filter["type"] == "date" || $isExtJs6 && in_array($fieldname, array("modificationDate", "creationdate"))) {
                 if ($filter[$operatorField] == "lt") {
                     $operator = "<";
                 } else {
                     if ($filter[$operatorField] == "gt") {
                         $operator = ">";
                     } else {
                         if ($filter[$operatorField] == "eq") {
                             $operator = "=";
                         }
                     }
                 }
                 $filter["value"] = strtotime($filter["value"]);
                 $field = "`" . $fieldname . "` ";
                 $value = $filter["value"];
             }
             if ($field && $value) {
                 $conditionFilters[] = $field . $operator . " " . $db->quote($value);
             }
         }
     }
     if ($this->getParam("searchString")) {
         $filterTerm = $db->quote("%" . mb_strtolower($this->getParam("searchString")) . "%");
         $conditionFilters[] = "(lower(`key`) LIKE " . $filterTerm . " OR lower(`text`) LIKE " . $filterTerm . ")";
     }
     if (!empty($conditionFilters)) {
         return implode(" AND ", $conditionFilters);
     }
     return null;
 }
Ejemplo n.º 19
0
 public function indexAction()
 {
     // IE compatibility
     //$this->getResponse()->setHeader("X-UA-Compatible", "IE=8; IE=9", true);
     // clear open edit locks for this session (in the case of a reload, ...)
     \Pimcore\Model\Element\Editlock::clearSession(session_id());
     // check maintenance
     $maintenance_enabled = false;
     $manager = Model\Schedule\Manager\Factory::getManager("maintenance.pid");
     $lastExecution = $manager->getLastExecution();
     if ($lastExecution) {
         if (time() - $lastExecution < 610) {
             // maintenance script should run at least every 10 minutes + a little tolerance
             $maintenance_enabled = true;
         }
     }
     $this->view->maintenance_enabled = \Zend_Json::encode($maintenance_enabled);
     // configuration
     $sysConfig = Config::getSystemConfig();
     $this->view->config = $sysConfig;
     //mail settings
     $mailIncomplete = false;
     if ($sysConfig->email) {
         if (!$sysConfig->email->debug->emailaddresses) {
             $mailIncomplete = true;
         }
         if (!$sysConfig->email->sender->email) {
             $mailIncomplete = true;
         }
         if ($sysConfig->email->method == "smtp" && !$sysConfig->email->smtp->host) {
             $mailIncomplete = true;
         }
     }
     $this->view->mail_settings_complete = \Zend_Json::encode(!$mailIncomplete);
     // report configuration
     $this->view->report_config = Config::getReportConfig();
     // customviews config
     $cvConfig = Tool::getCustomViewConfig();
     $cvData = array();
     if ($cvConfig) {
         foreach ($cvConfig as $node) {
             $tmpData = $node;
             $rootNode = Model\Object::getByPath($tmpData["rootfolder"]);
             if ($rootNode) {
                 $tmpData["rootId"] = $rootNode->getId();
                 $tmpData["allowedClasses"] = explode(",", $tmpData["classes"]);
                 $tmpData["showroot"] = (bool) $tmpData["showroot"];
                 $cvData[] = $tmpData;
             }
         }
     }
     $this->view->customview_config = $cvData;
     // upload limit
     $max_upload = filesize2bytes(ini_get("upload_max_filesize") . "B");
     $max_post = filesize2bytes(ini_get("post_max_size") . "B");
     $upload_mb = min($max_upload, $max_post);
     $this->view->upload_max_filesize = $upload_mb;
     // csrf token
     $user = $this->getUser();
     $this->view->csrfToken = Tool\Session::useSession(function ($adminSession) use($user) {
         if (!isset($adminSession->csrfToken) && !$adminSession->csrfToken) {
             $adminSession->csrfToken = sha1(microtime() . $user->getName() . uniqid());
         }
         return $adminSession->csrfToken;
     });
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         $this->forward("index6");
     }
 }
Ejemplo n.º 20
0
 /**
  * @param array
  * @return void $assetTypes
  */
 public function setAssetTypes($assetTypes)
 {
     // this is the new method with Ext.form.MultiSelect
     if (is_string($assetTypes) && !empty($assetTypes) || \Pimcore\Tool\Admin::isExtJS6() && is_array($assetTypes)) {
         if (!\Pimcore\Tool\Admin::isExtJS6()) {
             $parts = explode(",", $assetTypes);
         } else {
             $parts = $assetTypes;
         }
         $assetTypes = array();
         foreach ($parts as $type) {
             $assetTypes[] = array("assetTypes" => $type);
         }
     }
     $this->assetTypes = $assetTypes;
     return $this;
 }
Ejemplo n.º 21
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $page = Document\Newsletter::getById($this->getParam("id"));
             $page = $this->getLatestVersion($page);
             $page->setUserModification($this->getUser()->getId());
             if ($this->getParam("task") == "unpublish") {
                 $page->setPublished(false);
             }
             if ($this->getParam("task") == "publish") {
                 $page->setPublished(true);
             }
             // only save when publish or unpublish
             if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
                 $this->setValuesToDocument($page);
                 try {
                     $page->save();
                     $this->saveToSession($page);
                     $this->_helper->json(["success" => true]);
                 } catch (\Exception $e) {
                     Logger::err($e);
                     $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                 }
             } else {
                 if ($page->isAllowed("save")) {
                     $this->setValuesToDocument($page);
                     try {
                         $page->saveVersion();
                         $this->saveToSession($page);
                         $this->_helper->json(["success" => true]);
                     } catch (\Exception $e) {
                         if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                             throw $e;
                         }
                         Logger::err($e);
                         $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         Logger::log($e);
         if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
             $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
         }
         throw $e;
     }
     $this->_helper->json(false);
 }
Ejemplo n.º 22
0
 /**
  * @param $filters
  * @param $fields
  * @param bool $ignoreSelectAndGroupBy
  * @param null $drillDownFilters
  * @param null $selectField
  * @return array
  */
 protected function getBaseQuery($filters, $fields, $ignoreSelectAndGroupBy = false, $drillDownFilters = null, $selectField = null)
 {
     $db = Resource::get();
     $condition = array("1 = 1");
     $sql = $this->buildQueryString($this->config, $ignoreSelectAndGroupBy, $drillDownFilters, $selectField);
     $data = "";
     if ($filters) {
         if (is_array($filters)) {
             foreach ($filters as $filter) {
                 if (\Pimcore\Tool\Admin::isExtJS6()) {
                     $operator = $filter['operator'];
                     switch ($operator) {
                         case 'like':
                             $condition[] = $db->quoteIdentifier($filter["property"]) . " LIKE " . $db->quote("%" . $filter["value"] . "%");
                             break;
                         case "lt":
                         case "gt":
                         case "eq":
                             $compMapping = array("lt" => "<", "gt" => ">", "eq" => "=");
                             $condition[] = $db->quoteIdentifier($filter["property"]) . " " . $compMapping[$operator] . " " . $db->quote($filter["value"]);
                             break;
                         case "=":
                             $condition[] = $db->quoteIdentifier($filter["property"]) . " = " . $db->quote((int) $filter["value"]);
                             break;
                     }
                 } else {
                     if ($filter["type"] == "string") {
                         $condition[] = $db->quoteIdentifier($filter["field"]) . " LIKE " . $db->quote("%" . $filter["value"] . "%");
                     } else {
                         if ($filter["type"] == "numeric") {
                             $compMapping = array("lt" => "<", "gt" => ">", "eq" => "=");
                             if ($compMapping[$filter["comparison"]]) {
                                 $condition[] = $db->quoteIdentifier($filter["field"]) . " " . $compMapping[$filter["comparison"]] . " " . $db->quote($filter["value"]);
                             }
                         } else {
                             if ($filter["type"] == "boolean") {
                                 $condition[] = $db->quoteIdentifier($filter["field"]) . " = " . $db->quote((int) $filter["value"]);
                             } else {
                                 if ($filter["type"] == "date") {
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!preg_match("/(ALTER|CREATE|DROP|RENAME|TRUNCATE|UPDATE|DELETE) /i", $sql, $matches)) {
         $condition = implode(" AND ", $condition);
         $total = "SELECT COUNT(*) FROM (" . $sql . ") AS somerandxyz WHERE " . $condition;
         if ($fields) {
             $data = "SELECT `" . implode("`, `", $fields) . "` FROM (" . $sql . ") AS somerandxyz WHERE " . $condition;
         } else {
             $data = "SELECT * FROM (" . $sql . ") AS somerandxyz WHERE " . $condition;
         }
     } else {
         return;
     }
     return array("data" => $data, "count" => $total);
 }
Ejemplo n.º 23
0
 public function getLanguageFlagAction()
 {
     $iconPath = Tool::getLanguageFlagFile($this->getParam("language"));
     if (Tool\Admin::isExtJS6()) {
         header("Content-Type: image/svg+xml");
     } else {
         header("Content-Type: image/png");
     }
     echo file_get_contents($iconPath);
     exit;
 }
Ejemplo n.º 24
0
 public function fileexplorerTreeAction()
 {
     $this->checkPermission("fileexplorer");
     $referencePath = $this->getFileexplorerPath("node");
     $items = scandir($referencePath);
     $contents = array();
     foreach ($items as $item) {
         if ($item == "." || $item == "..") {
             continue;
         }
         $file = $referencePath . "/" . $item;
         $file = str_replace("//", "/", $file);
         if (is_dir($file) || is_file($file)) {
             $itemConfig = array("id" => "/fileexplorer" . str_replace(PIMCORE_DOCUMENT_ROOT, "", $file), "text" => $item, "leaf" => true, "writeable" => is_writable($file));
             if (is_dir($file)) {
                 $itemConfig["leaf"] = false;
                 $itemConfig["type"] = "folder";
                 if (\Pimcore\Tool\Admin::isExtJS6() && is_dir_empty($file)) {
                     $itemConfig["loaded"] = true;
                 }
                 $itemConfig["expandable"] = true;
             } elseif (is_file($file)) {
                 $itemConfig["type"] = "file";
             }
             $contents[] = $itemConfig;
         }
     }
     $this->_helper->json($contents);
 }
Ejemplo n.º 25
0
 /**
  * @param Object\AbstractObject $child
  * @return array
  */
 protected function getTreeNodeConfig($element)
 {
     $child = $element;
     $tmpObject = array("id" => $child->getId(), "text" => $child->getKey(), "type" => $child->getType(), "path" => $child->getFullPath(), "basePath" => $child->getPath(), "elementType" => "object", "locked" => $child->isLocked(), "lockOwner" => $child->getLocked() ? true : false);
     $hasChildren = $child->hasChilds([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_FOLDER, Object\AbstractObject::OBJECT_TYPE_VARIANT]);
     $tmpObject["isTarget"] = false;
     $tmpObject["allowDrop"] = false;
     $tmpObject["allowChildren"] = false;
     $tmpObject["leaf"] = !$hasChildren;
     $tmpObject["isTarget"] = true;
     if ($tmpObject["type"] != "variant") {
         $tmpObject["allowDrop"] = true;
     }
     $tmpObject["allowChildren"] = true;
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         $tmpObject["leaf"] = !$hasChildren;
     } else {
         $tmpObject["leaf"] = false;
     }
     $tmpObject["cls"] = "";
     $tmpObject["qtipCfg"] = $child->getElementAdminStyle()->getElementQtipConfig();
     if ($child->getType() != "folder") {
         $tmpObject["published"] = $child->isPublished();
         $tmpObject["className"] = $child->getClass()->getName();
         if (!$child->isPublished()) {
             $tmpObject["cls"] .= "pimcore_unpublished ";
         }
         $tmpObject["allowVariants"] = $child->getClass()->getAllowVariants();
     }
     if ($tmpObject["type"] == "variant") {
         $tmpObject["iconCls"] = "pimcore_icon_tree_variant";
     } else {
         if ($child->getElementAdminStyle()->getElementIcon()) {
             $tmpObject["icon"] = $child->getElementAdminStyle()->getElementIcon();
         }
         if ($child->getElementAdminStyle()->getElementIconClass()) {
             $tmpObject["iconCls"] = $child->getElementAdminStyle()->getElementIconClass();
         }
     }
     if ($child->getElementAdminStyle()->getElementCssClass()) {
         $tmpObject["cls"] .= $child->getElementAdminStyle()->getElementCssClass() . " ";
     }
     $tmpObject["expanded"] = !$hasChildren;
     $tmpObject["permissions"] = $child->getUserPermissions($this->getUser());
     if ($child->isLocked()) {
         $tmpObject["cls"] .= "pimcore_treenode_locked ";
     }
     if ($child->getLocked()) {
         $tmpObject["cls"] .= "pimcore_treenode_lockOwner ";
     }
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         if ($tmpObject["leaf"]) {
             $tmpObject["expandable"] = false;
             $tmpObject["expanded"] = true;
             $tmpObject["leaf"] = false;
             $tmpObject["loaded"] = true;
         }
     }
     return $tmpObject;
 }
Ejemplo n.º 26
0
 protected function getToolBarDefaultConfig()
 {
     $buttonWidth = 168;
     // @extjs6
     if (!\Pimcore\Tool\Admin::isExtJS6()) {
         $buttonWidth = 154;
     }
     return array("areablock_toolbar" => array("title" => "", "width" => 172, "x" => 20, "y" => 50, "xAlign" => "left", "buttonWidth" => $buttonWidth, "buttonMaxCharacters" => 20));
 }
Ejemplo n.º 27
0
 /**
  * CUSTOM VIEWS
  */
 public function saveCustomviewsAction()
 {
     $success = true;
     $settings = ["views" => []];
     for ($i = 0; $i < 1000; $i++) {
         if ($this->getParam("name_" . $i)) {
             $classes = $this->getParam("classes_" . $i);
             if (is_array($classes) || \Pimcore\Tool\Admin::isExtJS6()) {
                 $classes = implode(',', $classes);
             }
             // check for root-folder
             $rootfolder = "/";
             if ($this->getParam("rootfolder_" . $i)) {
                 $rootfolder = $this->getParam("rootfolder_" . $i);
             }
             $settings["views"][] = array("name" => $this->getParam("name_" . $i), "condition" => $this->getParam("condition_" . $i), "icon" => $this->getParam("icon_" . $i), "id" => $i + 1, "rootfolder" => $rootfolder, "showroot" => $this->getParam("showroot_" . $i) == "true" ? true : false, "classes" => $classes);
         }
     }
     $configFile = \Pimcore\Config::locateConfigFile("customviews.php");
     File::put($configFile, to_php_data_file_format($settings));
     $this->_helper->json(array("success" => $success));
 }
Ejemplo n.º 28
0
 /**
  * @see Model\Object\ClassDefinition\Data::getDataFromEditmode
  * @param string $data
  * @param null|Model\Object\AbstractObject $object
  * @return string
  */
 public function getDataFromEditmode($data, $object = null)
 {
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         return $data;
     } else {
         if (strlen($data)) {
             return explode(",", $data);
         }
     }
     return null;
 }
Ejemplo n.º 29
0
 protected function getRoleTreeNodeConfig($role)
 {
     $tmpUser = ["id" => $role->getId(), "text" => $role->getName(), "elementType" => "role", "qtipCfg" => ["title" => "ID: " . $role->getId()]];
     // set type specific settings
     if ($role instanceof User\Role\Folder) {
         $tmpUser["leaf"] = false;
         $tmpUser["iconCls"] = "pimcore_icon_folder";
         $tmpUser["expanded"] = true;
         $tmpUser["allowChildren"] = true;
         if ($role->hasChilds()) {
             $tmpUser["expanded"] = false;
         } elseif (\Pimcore\Tool\Admin::isExtJS6()) {
             $tmpUser["loaded"] = true;
         }
     } else {
         $tmpUser["leaf"] = true;
         $tmpUser["iconCls"] = "pimcore_icon_roles";
         $tmpUser["allowChildren"] = false;
     }
     return $tmpUser;
 }
Ejemplo n.º 30
0
 protected function getGridFilterCondition($tableName, $languageMode = false)
 {
     $joins = [];
     $conditions = [];
     $validLanguages = $this->getUser()->getAllowedLanguagesForViewingWebsiteTranslations();
     $db = \Pimcore\Db::get();
     $conditionFilters = [];
     $filterJson = $this->getParam("filter");
     if ($filterJson) {
         $isExtJs6 = \Pimcore\Tool\Admin::isExtJS6();
         if ($isExtJs6) {
             $propertyField = "property";
             $operatorField = "operator";
         } else {
             $propertyField = "field";
             $operatorField = "comparison";
         }
         $filters = \Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             $field = null;
             $value = null;
             if (!$languageMode && in_array($filter[$propertyField], $validLanguages) || $languageMode && !in_array($filter[$propertyField], $validLanguages)) {
                 continue;
             }
             if ($languageMode) {
                 $fieldname = $filter[$propertyField];
             } else {
                 $fieldname = $tableName . "." . $filter[$propertyField];
             }
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
                 $field = $fieldname;
                 $value = "%" . $filter["value"] . "%";
             } elseif ($filter["type"] == "date" || $isExtJs6 && in_array($fieldname, ["modificationDate", "creationdate"])) {
                 if ($filter[$operatorField] == "lt") {
                     $operator = "<";
                 } elseif ($filter[$operatorField] == "gt") {
                     $operator = ">";
                 } elseif ($filter[$operatorField] == "eq") {
                     $operator = "=";
                 }
                 $filter["value"] = strtotime($filter["value"]);
                 $field = $fieldname;
                 $value = $filter["value"];
             }
             if ($field && $value) {
                 $condition = $field . " " . $operator . " " . $db->quote($value);
                 if ($languageMode) {
                     $conditions[$filter[$propertyField]] = $condition;
                     $joins[] = ["language" => $filter[$propertyField]];
                 } else {
                     $conditionFilters[] = $condition;
                 }
             }
         }
     }
     if ($this->getParam("searchString")) {
         $filterTerm = $db->quote("%" . mb_strtolower($this->getParam("searchString")) . "%");
         $conditionFilters[] = "(lower(" . $tableName . ".key) LIKE " . $filterTerm . " OR lower(" . $tableName . ".text) LIKE " . $filterTerm . ")";
     }
     if ($languageMode) {
         $result = ["joins" => $joins, "conditions" => $conditions];
         return $result;
     } else {
         if (!empty($conditionFilters)) {
             return implode(" AND ", $conditionFilters);
         }
         return null;
     }
 }