/** * @param $name * * @return Model\Document\Page */ public function getElement($name) { $id = sprintf('%s%s%d', $name, $this->name, $this->index); $element = $this->doc->getElement($id); $element->suffixes = array($this->name); return $element; }
public function addLanguage($languageToAdd) { // Check if language is not already added if (in_array($languageToAdd, Tool::getValidLanguages())) { $result = false; } else { // Read all the documents from the first language $availableLanguages = Tool::getValidLanguages(); $firstLanguageDocument = \Pimcore\Model\Document::getByPath('/' . reset($availableLanguages)); \Zend_Registry::set('SEI18N_add', 1); // Add the language main folder $document = Page::create(1, array('key' => $languageToAdd, "userOwner" => 1, "userModification" => 1, "published" => true, "controller" => 'default', "action" => 'go-to-first-child')); $document->setProperty('language', 'text', $languageToAdd); // Set the language to this folder and let it inherit to the child pages $document->setProperty('isLanguageRoot', 'text', 1, false, false); // Set as language root document $document->save(); // Add Link to other languages $t = new Keys(); $t->insert(array("document_id" => $document->getId(), "language" => $languageToAdd, "sourcePath" => $firstLanguageDocument->getFullPath())); // Lets add all the docs $this->addDocuments($firstLanguageDocument->getId(), $languageToAdd); \Zend_Registry::set('SEI18N_add', 0); $oldConfig = Config::getSystemConfig(); $settings = $oldConfig->toArray(); $languages = explode(',', $settings['general']['validLanguages']); $languages[] = $languageToAdd; $settings['general']['validLanguages'] = implode(',', $languages); $config = new \Zend_Config($settings, true); $writer = new \Zend_Config_Writer_Xml(array("config" => $config, "filename" => PIMCORE_CONFIGURATION_SYSTEM)); $writer->write(); $result = true; } return $result; }
/** * @param $name * * @return Model\Document\Tag */ public function getElement($name) { $root = $name . implode('_', $this->suffixes); foreach ($this->suffixes as $item) { if (preg_match('#[^\\d]{1}(?<index>[\\d]+)$#i', $item, $match)) { $root .= $match['index'] . '_'; } } $root .= $this->index; $id = $root; $element = $this->doc->getElement($id); if ($element) { $element->suffixes = $this->suffixes; } return $element; }
/** * @throws Exception */ public function languageDetectionAction() { // Get the browser language $locale = new Zend_Locale(); $browserLanguage = $locale->getLanguage(); $languages = Tool::getValidLanguages(); // Check if the browser language is a valid frontend language if (in_array($browserLanguage, $languages)) { $language = $browserLanguage; } else { // If it is not, take the first frontend language as default $language = reset($languages); } // Get the folder of the current language (in the current site) $currentSitePath = $this->document->getRealFullPath(); $folder = Document\Page::getByPath($currentSitePath . '/' . $language); if ($folder) { $document = $this->findFirstDocumentByParentId($folder->getId()); if ($document) { $this->redirect($document->getPath() . $document->getKey()); } else { throw new Exception('No document found in your browser language'); } } else { throw new Exception('No language folder found that matches your browser language'); } }
/** * @param boolean $callParent * @return string */ public function getKeywords($callParent = true) { if ($callParent) { return parent::getKeywords(); } foreach ($this->getPagesOnPath() as $page) { if ($page->getKeywords()) { return $page->getKeywords(); } } return ''; }
/** * @return Block\Item[] */ public function getElements() { // init $doc = Model\Document\Page::getById($this->getDocumentId()); $suffixes = (array) $this->suffixes; $suffixes[] = $this->getName(); $list = array(); foreach ($this->getData() as $index) { $list[] = new Block\Item($doc, $index, $suffixes); } return $list; }
public function saveAction() { if ($this->getParam("id")) { $page = Document\Page::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); } $settings = array(); 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 = array(); 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 = array(); for ($i = 1; $i < 30; $i++) { if (array_key_exists("metadata_idName_" . $i, $settings)) { $metaData[] = array("idName" => $settings["metadata_idName_" . $i], "idValue" => $settings["metadata_idValue_" . $i], "contentName" => $settings["metadata_contentName_" . $i], "contentValue" => $settings["metadata_contentValue_" . $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(array("success" => true)); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->saveToSession($page); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
public function addAction() { $success = false; $errorMessage = ""; // check for permission $parentDocument = Document::getById(intval($this->getParam("parentId"))); if ($parentDocument->isAllowed("create")) { $intendedPath = $parentDocument->getFullPath() . "/" . $this->getParam("key"); if (!Document\Service::pathExists($intendedPath)) { $createValues = array("userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId(), "published" => false); $createValues["key"] = $this->getParam("key"); // check for a docType $docType = Document\DocType::getById(intval($this->getParam("docTypeId"))); if ($docType) { $createValues["template"] = $docType->getTemplate(); $createValues["controller"] = $docType->getController(); $createValues["action"] = $docType->getAction(); $createValues["module"] = $docType->getModule(); } else { if ($this->getParam("type") == "page" || $this->getParam("type") == "snippet" || $this->getParam("type") == "email") { $createValues["controller"] = Config::getSystemConfig()->documents->default_controller; $createValues["action"] = Config::getSystemConfig()->documents->default_action; } } switch ($this->getParam("type")) { case "page": $document = Document\Page::create($this->getParam("parentId"), $createValues, false); $document->setTitle($this->getParam('title', null)); $document->setProperty("navigation_name", "text", $this->getParam('name', null), false); $document->save(); $success = true; break; case "snippet": $document = Document\Snippet::create($this->getParam("parentId"), $createValues); $success = true; break; case "email": //ckogler $document = Document\Email::create($this->getParam("parentId"), $createValues); $success = true; break; case "link": $document = Document\Link::create($this->getParam("parentId"), $createValues); $success = true; break; case "hardlink": $document = Document\Hardlink::create($this->getParam("parentId"), $createValues); $success = true; break; case "folder": $document = Document\Folder::create($this->getParam("parentId"), $createValues); $document->setPublished(true); try { $document->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } break; default: $classname = "\\Pimcore\\Model\\Document\\" . ucfirst($this->getParam("type")); // this is the fallback for custom document types using prefixes // so we need to check if the class exists first if (!\Pimcore\Tool::classExists($classname)) { $oldStyleClass = "\\Document_" . ucfirst($this->getParam("type")); if (\Pimcore\Tool::classExists($oldStyleClass)) { $classname = $oldStyleClass; } } if (Tool::classExists($classname)) { $document = $classname::create($this->getParam("parentId"), $createValues); try { $document->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } break; } else { \Logger::debug("Unknown document type, can't add [ " . $this->getParam("type") . " ] "); } break; } } else { $errorMessage = "prevented adding a document because document with same path+key [ {$intendedPath} ] already exists"; \Logger::debug($errorMessage); } } else { $errorMessage = "prevented adding a document because of missing permissions"; \Logger::debug($errorMessage); } if ($success) { $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType())); } else { $this->_helper->json(array("success" => $success, "message" => $errorMessage)); } }
/** * @param $name * * @return Model\Document\Tag */ public function getElement($name) { // init $doc = Model\Document\Page::getById($this->getDocumentId()); $id = sprintf('%s%s%d', $name, $this->getName(), 1); $element = $doc->getElement($id); $element->suffixes = array($this->getName()); return $element; }
/** * @param $name * * @return Areablock\Item[] */ public function getElement($name) { // init $doc = Model\Document\Page::getById($this->getDocumentId()); $list = array(); foreach ($this->getData() as $index => $item) { if ($item['type'] == $name) { $list[$index] = new Areablock\Item($doc, $this->getName(), $item['key']); } } return $list; }
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); }
public static function setup() { // Reset first page $document = Document\Page::getById(1); $document->setModule("Multilingual"); $document->setController("default"); $document->setAction('language-detection'); $document->save(); // Add predefined property $property = Property\Predefined::create(); $property->setValues(array('key' => 'doNotSyncProperties', 'name' => 'Multilingual: Do not sync properties', 'description' => 'Do not sync properties across documents in other languages', 'data' => 1, 'type' => 'bool', 'ctype' => 'document', 'inheritable' => false)); $property->save(); }
private function createEmailDocuments() { try { $email = Email::getByPath(self::DOCUMENT_EMAIL_CONFIRMATION_PATH); if (!is_object($email)) { $email = new Email(); $email->setParent(Page::getByPath(dirname(self::DOCUMENT_EMAIL_CONFIRMATION_PATH))); $email->setKey(basename(self::DOCUMENT_EMAIL_CONFIRMATION_PATH)); $email->setModule(self::CLASS_PARTICIPATION_NAME); $email->setController('Email'); $email->setAction('confirmation'); $email->setSubject(self::EMAIL_CONFIRMATION_SUBJECT_DEFAULT); $email->save(); } } catch (\Exception $exception) { throw new \Exception('Unable to create email document page [' . Plugin::DOCUMENT_EMAIL_CONFIRMATION_PATH . ']: ' . $exception->getMessage()); } }