public function saveAction() { if ($this->_getParam("id")) { $page = Document_Email::getById($this->_getParam("id")); $page = $this->getLatestVersion($page); $page->getPermissionsForUser($this->getUser()); $page->setUserModification($this->getUser()->getId()); // save to session $key = "document_" . $this->_getParam("id"); $session = new Zend_Session_Namespace("pimcore_documents"); $session->{$key} = $page; 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->_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->_helper->json(array("success" => true)); } catch (Exception $e) { Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
/** * Helper to validate a email address * * @static * @param $emailAddress * @return string | null - returns "null" if the email address is invalid otherwise the email address is returned */ public static function validateEmailAddress($emailAddress) { if (is_null(self::$validator)) { self::$validator = new Zend_Validate_EmailAddress(); } $emailAddress = trim($emailAddress); if (self::$validator->isValid($emailAddress)) { return $emailAddress; } }
public function addAction() { $success = false; // 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 if ($this->_getParam("docTypeId") && is_numeric($this->_getParam("docTypeId"))) { $docType = Document_DocType::getById(intval($this->_getParam("docTypeId"))); $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"] = Pimcore_Config::getSystemConfig()->documents->default_controller; $createValues["action"] = Pimcore_Config::getSystemConfig()->documents->default_action; } } switch ($this->_getParam("type")) { case "page": $document = Document_Page::create($this->_getParam("parentId"), $createValues); $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: Logger::debug("Unknown document type, can't add [ " . $this->_getParam("type") . " ] "); break; } } else { Logger::debug("prevented adding a document because document with same path+key [ {$intendedPath} ] already exists"); } } else { Logger::debug("prevented adding a document because of missing permissions"); } if ($success) { $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType())); } else { $this->_helper->json(array("success" => $success)); } }