protected function setValuesToDocument(Document\Link $link) { // data if ($this->getParam("data")) { $data = \Zend_Json::decode($this->getParam("data")); if (!empty($data["path"])) { if ($document = Document::getByPath($data["path"])) { $data["linktype"] = "internal"; $data["internalType"] = "document"; $data["internal"] = $document->getId(); } elseif ($asset = Asset::getByPath($data["path"])) { $data["linktype"] = "internal"; $data["internalType"] = "asset"; $data["internal"] = $asset->getId(); } else { $data["linktype"] = "direct"; $data["direct"] = $data["path"]; } } else { // clear content of link $data["linktype"] = "internal"; $data["direct"] = ""; $data["internalType"] = null; $data["internal"] = null; } unset($data["path"]); $link->setValues($data); } $this->addPropertiesToDocument($link); }
public function subscribeAction() { $this->enableLayout(); $newsletter = new Newsletter("person"); // replace "crm" with the class name you have used for your class above (mailing list) $params = $this->getAllParams(); $this->view->success = false; if ($newsletter->checkParams($params)) { try { $params["parentId"] = 1; // default folder (home) where we want to save our subscribers $newsletterFolder = Model\Object::getByPath("/crm/newsletter"); if ($newsletterFolder) { $params["parentId"] = $newsletterFolder->getId(); } $user = $newsletter->subscribe($params); // user and email document // parameters available in the email: gender, firstname, lastname, email, token, object // ==> see mailing framework $newsletter->sendConfirmationMail($user, Model\Document::getByPath("/en/advanced-examples/newsletter/confirmation-email"), ["additional" => "parameters"]); // do some other stuff with the new user $user->setDateRegister(new \DateTime()); $user->save(); $this->view->success = true; } catch (\Exception $e) { echo $e->getMessage(); } } }
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; }
/** * @see Document\Tag\TagInterface::setDataFromEditmode * @param mixed $data * @return void */ public function setDataFromEditmode($data) { if (!is_array($data)) { $data = array(); } if ($doc = Document::getByPath($data['path'])) { if ($doc instanceof Document) { $data['internal'] = true; $data['internalId'] = $doc->getId(); $data['internalType'] = 'document'; } //its an object? } else { if (strpos($data['path'], '::') !== FALSE) { $data['internal'] = true; $data['internalType'] = 'object'; } } if (!$data['internal']) { if ($asset = Asset::getByPath($data['path'])) { if ($asset instanceof Asset) { $data['internal'] = true; $data['internalId'] = $asset->getId(); $data['internalType'] = 'asset'; } } } $this->data = $data; return $this; }
/** * @param object $participation * @return void * @throws \Exception */ public function sendEmail($participation) { $email = $participation->getEmail(); $emailDomain = trim(strtolower(preg_replace('/^[^@]+@/', '', $email))); $participation->setEmailDomain($emailDomain); $participation->save(); $confirmationLink = $this->createConfirmationLink($participation->getConfirmationCode()); $parameters = array('confirmationLink' => $confirmationLink, 'participationId' => $participation->getId()); $emailDocumentPath = Plugin::getConfig()->get('emailDocumentPath'); $emailDocument = DocumentModel::getByPath($emailDocumentPath); if (!$emailDocument instanceof EmailDocument) { throw new \Exception("Error: emailDocumentPath [{$emailDocumentPath}] " . "is not a valid email document."); } $mail = new Mail(); $mail->addTo($email); if ($this->getSubject()) { $mail->setSubject($this->getSubject()); } $mail->setDocument($emailDocumentPath); $mail->setParams($parameters); $mail->send(); $note = new Note(); $note->setElement($participation); $note->setDate(time()); $note->setType("confirmation"); $note->setTitle("Email sent"); $note->addData("email", "text", $email); $note->setUser(0); $note->save(); }
/** * @param \Zend_Controller_Request_Abstract $request * @throws mixed */ protected function _handleError(\Zend_Controller_Request_Abstract $request) { // remove zend error handler $front = \Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler"); $response = $this->getResponse(); if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { // get errorpage try { // enable error handler $front->setParam('noErrorHandler', false); $errorPath = Config::getSystemConfig()->documents->error_pages->default; if (Site::isSiteRequest()) { $site = Site::getCurrentSite(); $errorPath = $site->getErrorDocument(); } if (empty($errorPath)) { $errorPath = "/"; } $document = Document::getByPath($errorPath); if (!$document instanceof Document\Page) { // default is home $document = Document::getById(1); } if ($document instanceof Document\Page) { $params = Tool::getRoutingDefaults(); if ($module = $document->getModule()) { $params["module"] = $module; } if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } $this->setErrorHandler($params); $request->setParam("document", $document); \Zend_Registry::set("pimcore_error_document", $document); // ensure that a viewRenderer exists, and is enabled if (!\Zend_Controller_Action_HelperBroker::hasHelper("viewRenderer")) { $viewRenderer = new \Pimcore\Controller\Action\Helper\ViewRenderer(); \Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); } $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer"); $viewRenderer->setNoRender(false); if ($viewRenderer->view === null) { $viewRenderer->initView(PIMCORE_WEBSITE_PATH . "/views"); } } } catch (\Exception $e) { \Logger::emergency("error page not found"); } } // call default ZF error handler parent::_handleError($request); }
protected function setValuesToDocument(Document\Hardlink $link) { // data $data = \Zend_Json::decode($this->getParam("data")); $sourceId = null; if ($sourceDocument = Document::getByPath($data["sourcePath"])) { $sourceId = $sourceDocument->getId(); } $link->setSourceId($sourceId); $link->setValues($data); $this->addPropertiesToDocument($link); }
private function getErrorDocument() { $config = Config::getSystemConfig(); $errorDocPath = $config->documents->error_pages->default; if (Site::isSiteRequest()) { $site = Site::getCurrentSite(); $errorDocPath = $site->getErrorDocument(); } $errorDoc = Document::getByPath($errorDocPath); \Zend_Registry::set("pimcore_error_document", $errorDoc); return $errorDoc; }
public function updateAction() { $letter = Newsletter\Config::getByName($this->getParam("name")); $data = \Zend_Json::decode($this->getParam("configuration")); if ($emailDoc = Document::getByPath($data["document"])) { $data["document"] = $emailDoc->getId(); } foreach ($data as $key => $value) { $setter = "set" . ucfirst($key); if (method_exists($letter, $setter)) { $letter->{$setter}($value); } } $letter->save(); $this->_helper->json(["success" => true]); }
/** * @param $googleResponse */ public function readGoogleResponse($googleResponse) { $googleResponse = $googleResponse["modelData"]; $this->setRaw($googleResponse); // available factes if (array_key_exists("context", $googleResponse) && is_array($googleResponse["context"])) { if (array_key_exists("facets", $googleResponse["context"]) && is_array($googleResponse["context"]["facets"])) { $facets = array(); foreach ($googleResponse["context"]["facets"] as $facet) { $facets[$facet[0]["label"]] = $facet[0]["anchor"]; } $this->setFacets($facets); } } // results incl. promotions, search results, ... $items = array(); // set promotions if (array_key_exists("promotions", $googleResponse) && is_array($googleResponse["promotions"])) { foreach ($googleResponse["promotions"] as $promo) { $promo["type"] = "promotion"; $promo["formattedUrl"] = preg_replace("@^https?://@", "", $promo["link"]); $promo["htmlFormattedUrl"] = $promo["formattedUrl"]; $items[] = new Item($promo); } } // set search results $total = intval($googleResponse["searchInformation"]["totalResults"]); if ($total > 100) { $total = 100; } $this->setTotal($total); if (array_key_exists("items", $googleResponse) && is_array($googleResponse["items"])) { foreach ($googleResponse["items"] as $item) { // check for relation to document or asset // first check for an image if (array_key_exists("pagemap", $item) && is_array($item["pagemap"])) { if (array_key_exists("cse_image", $item["pagemap"]) && is_array($item["pagemap"]["cse_image"])) { if ($item["pagemap"]["cse_image"][0]) { // try to get the asset id if (preg_match("/thumb_([0-9]+)__/", $item["pagemap"]["cse_image"][0]["src"], $matches)) { $test = $matches; if ($matches[1]) { if ($image = Model\Asset::getById($matches[1])) { if ($image instanceof Model\Asset\Image) { $item["image"] = $image; } } } } if (!array_key_exists("image", $item)) { $item["image"] = $item["pagemap"]["cse_image"][0]["src"]; } } } } // now a document $urlParts = parse_url($item["link"]); if ($document = Model\Document::getByPath($urlParts["path"])) { $item["document"] = $document; } $item["type"] = "searchresult"; $items[] = new Item($item); } } $this->setResults($items); }
/** * @param Document\Hardlink $hardlink * @param $path * @return Document */ public static function getNearestChildByPath(Document\Hardlink $hardlink, $path) { if ($hardlink->getChildsFromSource() && $hardlink->getSourceDocument()) { $hardlinkRealPath = preg_replace("@^" . preg_quote($hardlink->getRealFullPath()) . "@", $hardlink->getSourceDocument()->getRealFullPath(), $path); $pathes = array(); $pathes[] = "/"; $pathParts = explode("/", $hardlinkRealPath); $tmpPathes = array(); foreach ($pathParts as $pathPart) { $tmpPathes[] = $pathPart; $t = implode("/", $tmpPathes); if (!empty($t)) { $pathes[] = $t; } } $pathes = array_reverse($pathes); foreach ($pathes as $p) { $hardLinkedDocument = Document::getByPath($p); if ($hardLinkedDocument instanceof Document) { $hardLinkedDocument = self::wrap($hardLinkedDocument); $hardLinkedDocument->setHardLinkSource($hardlink); $_path = $path != "/" ? $_path = dirname($p) : $p; $_path = str_replace("\\", "/", $_path); // windows patch $_path .= $_path != "/" ? "/" : ""; $_path = preg_replace("@^" . preg_quote($hardlink->getSourceDocument()->getRealPath()) . "@", $hardlink->getRealPath(), $_path); $hardLinkedDocument->setPath($_path); return $hardLinkedDocument; } } } }
public function removeDocuments() { $file = sprintf('%s/documents.json', $this->baseDir); $docs = new \Zend_Config_Json($file); $root = reset($docs->toArray()); $doc = Document::getByPath('/' . ltrim($root['parent'] . '/' . $root['key'], '/')); if ($doc) { $doc->delete(); } }
/** * @throws \Exception */ public function correctPath() { // set path if ($this->getId() != 1) { // not for the root node if ($this->getParentId() == $this->getId()) { throw new \Exception("ParentID and ID is identical, an element can't be the parent of itself."); } $parent = Document::getById($this->getParentId()); if ($parent) { // use the parent's path from the database here (getCurrentFullPath), to ensure the path really exists and does not rely on the path // that is currently in the parent object (in memory), because this might have changed but wasn't not saved $this->setPath(str_replace("//", "/", $parent->getCurrentFullPath() . "/")); } else { // parent document doesn't exist anymore, set the parent to to root $this->setParentId(1); $this->setPath("/"); } if (strlen($this->getKey()) < 1) { $this->setKey("---no-valid-key---" . $this->getId()); throw new \Exception("Document requires key, generated key automatically"); } } else { if ($this->getId() == 1) { // some data in root node should always be the same $this->setParentId(0); $this->setPath("/"); $this->setKey(""); $this->setType("page"); } } if (Document\Service::pathExists($this->getRealFullPath())) { $duplicate = Document::getByPath($this->getRealFullPath()); if ($duplicate instanceof Document and $duplicate->getId() != $this->getId()) { throw new \Exception("Duplicate full path [ " . $this->getRealFullPath() . " ] - cannot save document"); } } if (strlen($this->getRealFullPath()) > 765) { throw new \Exception("Full path is limited to 765 characters, reduce the length of your parent's path"); } }
/** * @see Document\Tag\TagInterface::setDataFromEditmode * @param mixed $data * @return void */ public function setDataFromEditmode($data) { if (!is_array($data)) { $data = array(); } if ($doc = Document::getByPath($data["path"])) { if ($doc instanceof Document) { $data["internal"] = true; $data["internalId"] = $doc->getId(); $data["internalType"] = "document"; } } if (!$data["internal"]) { if ($asset = Asset::getByPath($data["path"])) { if ($asset instanceof Asset) { $data["internal"] = true; $data["internalId"] = $asset->getId(); $data["internalType"] = "asset"; } } } $this->data = $data; return $this; }
/** * fills object field data values from CSV Import String * @abstract * @param string $importValue * @param null|Model\Object\AbstractObject $object * @param mixed $params * @return Object\ClassDefinition\Data */ public function getFromCsvImport($importValue, $object = null, $params = []) { $values = explode(",", $importValue); $value = []; foreach ($values as $element) { $tokens = explode(":", $element); if (count($tokens) == 2) { $type = $tokens[0]; $path = $tokens[1]; $value[] = Element\Service::getElementByPath($type, $path); } else { //fallback for old export files if ($el = Asset::getByPath($element)) { $value[] = $el; } elseif ($el = Document::getByPath($element)) { $value[] = $el; } elseif ($el = Object::getByPath($element)) { $value[] = $el; } } } return $value; }
/** * */ public function restore() { $raw = file_get_contents($this->getStoreageFile()); $element = Serialize::unserialize($raw); // check for element with the same name if ($element instanceof Document) { $indentElement = Document::getByPath($element->getFullpath()); if ($indentElement) { $element->setKey($element->getKey() . "_restore"); } } else { if ($element instanceof Asset) { $indentElement = Asset::getByPath($element->getFullpath()); if ($indentElement) { $element->setFilename($element->getFilename() . "_restore"); } } else { if ($element instanceof Object\AbstractObject) { $indentElement = Object::getByPath($element->getFullpath()); if ($indentElement) { $element->setKey($element->getKey() . "_restore"); } } } } $this->restoreChilds($element); $this->delete(); }
public function translationCheckLanguageAction() { $success = false; $language = null; $document = Document::getByPath($this->getParam("path")); if ($document) { $language = $document->getProperty("language"); if ($language) { $success = true; } } $this->_helper->json(["success" => $success, "language" => $language]); }
public function navigationAction() { $config = Google\Analytics::getSiteConfig($this->getSite()); $startDate = date("Y-m-d", time() - 86400 * 31); $endDate = date("Y-m-d"); if ($this->getParam("dateFrom") && $this->getParam("dateTo")) { $startDate = date("Y-m-d", strtotime($this->getParam("dateFrom"))); $endDate = date("Y-m-d", strtotime($this->getParam("dateTo"))); } // all pageviews if ($filterPath = $this->getFilterPath()) { $filters[] = "ga:pagePath==" . $filterPath; } $opts = array("dimensions" => "ga:pagePath", "max-results" => 1, "sort" => "-ga:pageViews"); if (!empty($filters)) { $opts["filters"] = implode(";", $filters); } $result0 = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, "ga:pageViews", $opts); $totalViews = (int) $result0["totalsForAllResults"]["ga:pageViews"]; // ENTRANCES $opts = array("dimensions" => "ga:previousPagePath", "max-results" => 10, "sort" => "-ga:pageViews"); if (!empty($filters)) { $opts["filters"] = implode(";", $filters); } $result1 = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, "ga:pageViews", $opts); $prev = array(); foreach ($result1["rows"] as $row) { $d = array("path" => $this->formatDimension("ga:previousPagePath", $row[0]), "pageviews" => $row[1]); $document = Document::getByPath($row[0]); if ($document) { $d["id"] = $document->getId(); } $d["percent"] = round($d["pageviews"] / $totalViews * 100); $d["weight"] = 100; if ($prev[0]["weight"]) { $d["weight"] = round($d["percent"] / $prev[0]["percent"] * 100); } $prev[] = $d; } // EXITS $opts = array("dimensions" => "ga:pagePath", "max-results" => 10, "sort" => "-ga:pageViews"); if (!empty($filters)) { $opts["filters"] = implode(";", $filters); } $result2 = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, "ga:pageViews", $opts); $next = array(); foreach ($result2["rows"] as $row) { $d = array("path" => $this->formatDimension("ga:previousPagePath", $row[0]), "pageviews" => $row[1]); $document = Document::getByPath($row[0]); if ($document) { $d["id"] = $document->getId(); } $d["percent"] = round($d["pageviews"] / $totalViews * 100); $d["weight"] = 100; if ($next[0]["weight"]) { $d["weight"] = round($d["percent"] / $next[0]["percent"] * 100); } $next[] = $d; } $this->view->next = $next; $this->view->prev = $prev; $this->view->path = $this->getFilterPath(); $this->getResponse()->setHeader("Content-Type", "application/xml", true); }
/** * includes a document * * @param $include * @param array $params * @return string */ public function inc($include, $params = null, $cacheEnabled = true) { if (!is_array($params)) { $params = []; } // check if output-cache is enabled, if so, we're also using the cache here $cacheKey = null; $cacheConfig = false; if ($cacheEnabled) { if ($cacheConfig = Tool\Frontend::isOutputCacheEnabled()) { // cleanup params to avoid serializing Element\ElementInterface objects $cacheParams = $params; $cacheParams["~~include-document"] = $include; array_walk($cacheParams, function (&$value, $key) { if ($value instanceof Element\ElementInterface) { $value = $value->getId(); } elseif (is_object($value) && method_exists($value, "__toString")) { $value = (string) $value; } }); $cacheKey = "tag_inc__" . md5(serialize($cacheParams)); if ($content = Cache::load($cacheKey)) { return $content; } } } $editmodeBackup = \Zend_Registry::get("pimcore_editmode"); \Zend_Registry::set("pimcore_editmode", false); $includeBak = $include; // this is if $this->inc is called eg. with $this->href() as argument if (!$include instanceof Model\Document\PageSnippet && is_object($include) && method_exists($include, "__toString")) { $include = (string) $include; } if (is_string($include)) { try { $include = Model\Document::getByPath($include); } catch (\Exception $e) { $include = $includeBak; } } elseif (is_numeric($include)) { try { $include = Model\Document::getById($include); } catch (\Exception $e) { $include = $includeBak; } } $params = array_merge($params, array("document" => $include)); $content = ""; if ($include instanceof Model\Document\PageSnippet && $include->isPublished()) { if ($include->getAction() && $include->getController()) { $content = $this->action($include->getAction(), $include->getController(), $include->getModule(), $params); } elseif ($include->getTemplate()) { $content = $this->action("default", "default", null, $params); } // in editmode, we need to parse the returned html from the document include // add a class and the pimcore id / type so that it can be opened in editmode using the context menu // if there's no first level HTML container => add one (wrapper) if ($this->editmode) { include_once "simple_html_dom.php"; $editmodeClass = " pimcore_editable pimcore_tag_inc "; // this is if the content that is included does already contain markup/html // this is needed by the editmode to highlight included documents if ($html = str_get_html($content)) { $childs = $html->find("*"); if (is_array($childs)) { foreach ($childs as $child) { $child->class = $child->class . $editmodeClass; $child->pimcore_type = $include->getType(); $child->pimcore_id = $include->getId(); } } $content = $html->save(); $html->clear(); unset($html); } else { // add a div container if the include doesn't contain markup/html $content = '<div class="' . $editmodeClass . '" pimcore_id="' . $include->getId() . '" pimcore_type="' . $include->getType() . '">' . $content . '</div>'; } } // we need to add a component id to all first level html containers $componentId = ""; if ($this->document instanceof Model\Document) { $componentId .= 'document:' . $this->document->getId() . '.'; } $componentId .= 'type:inc.name:' . $include->getId(); $content = \Pimcore\Tool\Frontend::addComponentIdToHtml($content, $componentId); } \Zend_Registry::set("pimcore_editmode", $editmodeBackup); // write contents to the cache, if output-cache is enabled if ($cacheConfig) { Cache::save($content, $cacheKey, array("output", "output_inline"), $cacheConfig["lifetime"]); } return $content; }
public function getIdForPathAction() { if ($doc = Document::getByPath($this->getParam("path"))) { $this->_helper->json(array("id" => $doc->getId(), "type" => $doc->getType())); } else { $this->_helper->json(false); } $this->removeViewRenderer(); }
/** * @param $path * @param bool $ignoreHardlinks * @param array $types * @return Document|Document\PageSnippet|null|string */ protected function getNearestDocumentByPath($path, $ignoreHardlinks = false, $types = array()) { if ($this->nearestDocumentByPath instanceof Document) { $document = $this->nearestDocumentByPath; } else { $pathes = array(); $pathes[] = "/"; $pathParts = explode("/", $path); $tmpPathes = array(); foreach ($pathParts as $pathPart) { $tmpPathes[] = $pathPart; $t = implode("/", $tmpPathes); if (!empty($t)) { $pathes[] = $t; } } $pathes = array_reverse($pathes); foreach ($pathes as $p) { if ($document = Document::getByPath($p)) { if (empty($types) || in_array($document->getType(), $types)) { $this->nearestDocumentByPath = $document; break; } } else { if (Site::isSiteRequest()) { // also check for a pretty url in a site $site = Site::getCurrentSite(); $documentService = new Document\Service(); // undo the changed made by the site detection in self::match() $originalPath = preg_replace("@^" . $site->getRootPath() . "@", "", $p); $sitePrettyDocId = $documentService->getDocumentIdByPrettyUrlInSite($site, $originalPath); if ($sitePrettyDocId) { if ($sitePrettyDoc = Document::getById($sitePrettyDocId)) { $this->nearestDocumentByPath = $sitePrettyDoc; break; } } } } } } if ($document) { if (!$ignoreHardlinks) { if ($document instanceof Document\Hardlink) { if ($hardLinkedDocument = Document\Hardlink\Service::getNearestChildByPath($document, $path)) { $document = $hardLinkedDocument; } else { $document = Document\Hardlink\Service::wrap($document); } } } return $document; } return null; }
/** * @param $redirectUrl * @return $this */ public function setRedirectUrl($redirectUrl) { if (is_string($redirectUrl)) { if ($doc = Model\Document::getByPath($redirectUrl)) { $redirectUrl = $doc->getId(); } } $this->redirectUrl = $redirectUrl; return $this; }
public function glossaryAction() { if ($this->getParam("data")) { $this->checkPermission("glossary"); Cache::clearTag("glossary"); if ($this->getParam("xaction") == "destroy") { $data = \Zend_Json::decode($this->getParam("data")); if (\Pimcore\Tool\Admin::isExtJS6()) { $id = $data["id"]; } else { $id = $data; } $glossary = Glossary::getById($id); $glossary->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->getParam("xaction") == "update") { $data = \Zend_Json::decode($this->getParam("data")); // save glossary $glossary = Glossary::getById($data["id"]); if ($data["link"]) { if ($doc = Document::getByPath($data["link"])) { $tmpLink = $data["link"]; $data["link"] = $doc->getId(); } } $glossary->setValues($data); $glossary->save(); if ($link = $glossary->getLink()) { if (intval($link) > 0) { if ($doc = Document::getById(intval($link))) { $glossary->setLink($doc->getFullPath()); } } } $this->_helper->json(array("data" => $glossary, "success" => true)); } else { if ($this->getParam("xaction") == "create") { $data = \Zend_Json::decode($this->getParam("data")); unset($data["id"]); // save glossary $glossary = new Glossary(); if ($data["link"]) { if ($doc = Document::getByPath($data["link"])) { $tmpLink = $data["link"]; $data["link"] = $doc->getId(); } } $glossary->setValues($data); $glossary->save(); if ($link = $glossary->getLink()) { if (intval($link) > 0) { if ($doc = Document::getById(intval($link))) { $glossary->setLink($doc->getFullPath()); } } } $this->_helper->json(array("data" => $glossary, "success" => true)); } } } } else { // get list of glossaries $list = new Glossary\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']); } if ($this->getParam("filter")) { $list->setCondition("`text` LIKE " . $list->quote("%" . $this->getParam("filter") . "%")); } $list->load(); $glossaries = array(); foreach ($list->getGlossary() as $glossary) { if ($link = $glossary->getLink()) { if (intval($link) > 0) { if ($doc = Document::getById(intval($link))) { $glossary->setLink($doc->getFullPath()); } } } $glossaries[] = $glossary; } $this->_helper->json(array("data" => $glossaries, "success" => true, "total" => $list->getTotalCount())); } $this->_helper->json(false); }
/** * @param $document * @return $this * @throws \Exception */ public function setDocument($document) { if ($document instanceof Model\Document) { //document passed $this->document = $document; $this->setDocumentSettings(); } elseif ((int) $document > 0) { //id of document passed $this->setDocument(Model\Document::getById($document)); } elseif (is_string($document) && $document != "") { //path of document passed $this->setDocument(Model\Document::getByPath($document)); } else { throw new \Exception("{$document} is not an instance of \\Document\\Email or at least \\Document"); } return $this; }
/** * @param $path * @return $this */ public function setPath($path) { if (!empty($path)) { if ($document = Document::getByPath($path)) { $this->linktype = "internal"; $this->internalType = "document"; $this->internal = $document->getId(); } else { if ($asset = Asset::getByPath($path)) { $this->linktype = "internal"; $this->internalType = "asset"; $this->internal = $asset->getId(); } else { $this->linktype = "direct"; $this->direct = $path; } } } return $this; }
/** * @param $url * @return Document */ public static function getByUrl($url) { $urlParts = parse_url($url); if ($urlParts["path"]) { $document = Document::getByPath($urlParts["path"]); // search for a page in a site if (!$document) { $sitesList = new Model\Site\Listing(); $sitesObjects = $sitesList->load(); foreach ($sitesObjects as $site) { if ($site->getRootDocument() && (in_array($urlParts["host"], $site->getDomains()) || $site->getMainDomain() == $urlParts["host"])) { if ($document = Document::getByPath($site->getRootDocument() . $urlParts["path"])) { break; } } } } } return $document; }
/** * @param $importValue * @return mixed|null|Asset|Document|Element\ElementInterface */ public function getFromCsvImport($importValue) { $value = null; $values = explode(":", $importValue); if (count($values) == 2) { $type = $values[0]; $path = $values[1]; $value = Element\Service::getElementByPath($type, $path); } else { //fallback for old export files if ($el = Asset::getByPath($importValue)) { $value = $el; } else { if ($el = Document::getByPath($importValue)) { $value = $el; } else { if ($el = Object::getByPath($importValue)) { $value = $el; } } } } return $value; }
/** * @param int|null $contentMasterDocumentId */ public function setContentMasterDocumentId($contentMasterDocumentId) { // this is that the path is automatically converted to ID => when setting directly from admin UI if (!is_numeric($contentMasterDocumentId) && !empty($contentMasterDocumentId)) { $contentMasterDocument = Document::getByPath($contentMasterDocumentId); if ($contentMasterDocument instanceof Document\PageSnippet) { $contentMasterDocumentId = $contentMasterDocument->getId(); } } if (empty($contentMasterDocumentId)) { $contentMasterDocument = null; } if ($contentMasterDocumentId == $this->getId()) { throw new \Exception("You cannot use the current document as a master document, please choose a different one."); } $this->contentMasterDocumentId = $contentMasterDocumentId; return $this; }
/** * @param $element * @param $key * @param $path * @return string */ protected function getSaveCopyName($element, $key, $path) { if ($element instanceof Object\AbstractObject) { $equal = Object\AbstractObject::getByPath($path . "/" . $key); } else { if ($element instanceof Document) { $equal = Document::getByPath($path . "/" . $key); } else { if ($element instanceof Asset) { $equal = Asset::getByPath($path . "/" . $key); } } } if ($equal) { $key .= "_WScopy"; return $this->getSaveCopyName($element, $key, $path); } return $key; }
/** * @static * @param string $type * @param string $path * @return ElementInterface */ public static function getElementByPath($type, $path) { if ($type == "asset") { $element = Asset::getByPath($path); } else { if ($type == "object") { $element = Object::getByPath($path); } else { if ($type == "document") { $element = Document::getByPath($path); } } } return $element; }