Inheritance: extends Pimcore\Model\Element\AbstractElement
 public function codeAction()
 {
     $url = "";
     if ($this->getParam("name")) {
         $url = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . "/qr~-~code/" . $this->getParam("name");
     } elseif ($this->getParam("documentId")) {
         $doc = Document::getById($this->getParam("documentId"));
         $url = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . $doc->getFullPath();
     } elseif ($this->getParam("url")) {
         $url = $this->getParam("url");
     }
     $code = new \Endroid\QrCode\QrCode();
     $code->setText($url);
     $code->setPadding(0);
     $code->setSize(500);
     $hexToRGBA = function ($hex) {
         list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
         return ["r" => $r, "g" => $g, "b" => $b, "a" => 0];
     };
     if (strlen($this->getParam("foreColor", "")) == 7) {
         $code->setForegroundColor($hexToRGBA($this->getParam("foreColor")));
     }
     if (strlen($this->getParam("backgroundColor", "")) == 7) {
         $code->setBackgroundColor($hexToRGBA($this->getParam("backgroundColor")));
     }
     header("Content-Type: image/png");
     if ($this->getParam("download")) {
         $code->setSize(4000);
         header('Content-Disposition: attachment;filename="qrcode-' . $this->getParam("name", "preview") . '.png"', true);
     }
     $code->render();
     exit;
 }
 /**
  * @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();
 }
Example #3
0
File: Dao.php Project: sfie/pimcore
 /**
  * Loads a list of entries for the specicifies parameters, returns an array of Search\Backend\Data
  *
  * @return array
  */
 public function load()
 {
     $entries = array();
     $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($data as $entryData) {
         if ($entryData['maintype'] == 'document') {
             $element = Document::getById($entryData['id']);
         } else {
             if ($entryData['maintype'] == 'asset') {
                 $element = Asset::getById($entryData['id']);
             } else {
                 if ($entryData['maintype'] == 'object') {
                     $element = Object::getById($entryData['id']);
                 } else {
                     \Logger::err("unknown maintype ");
                 }
             }
         }
         if ($element) {
             $entry = new Search\Backend\Data();
             $entry->setId(new Search\Backend\Data\Id($element));
             $entry->setFullPath($entryData['fullpath']);
             $entry->setType($entryData['type']);
             $entry->setSubtype($entryData['subtype']);
             $entry->setUserOwner($entryData['userowner']);
             $entry->setUserModification($entryData['usermodification']);
             $entry->setCreationDate($entryData['creationdate']);
             $entry->setModificationDate($entryData['modificationdate']);
             $entry->setPublished($entryData['published'] === 0 ? false : true);
             $entries[] = $entry;
         }
     }
     $this->model->setEntries($entries);
     return $entries;
 }
 /**
  * @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;
 }
Example #5
0
 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();
         }
     }
 }
Example #7
0
 /**
  * @param $document
  * @param null $language
  * @return Document|null
  */
 public function inotherlang($document, $language = null)
 {
     $documentInOtherLang = null;
     if (is_null($language)) {
         $language = CURRENT_LANGUAGE;
     }
     if ($document instanceof Document) {
         $id = $document->getId();
     } elseif (is_numeric($document)) {
         $id = $document;
     } else {
         $id = 0;
     }
     $otherLangId = null;
     try {
         if (class_exists('\\Multilingual\\Document')) {
             $otherLangId = \Multilingual\Document::getDocumentIdInOtherLanguage($id, $language);
         } else {
             $otherLangId = $id;
         }
     } catch (Exception $e) {
     }
     if ($otherLangId) {
         $documentInOtherLang = Document::getById($otherLangId);
     }
     return $documentInOtherLang;
 }
Example #8
0
 private function doGetChildren(Document $document)
 {
     $children = $document->getChilds();
     foreach ($children as $child) {
         if ($child instanceof Document\Printpage) {
             $this->allChildren[] = $child;
         }
         if ($child instanceof Document\Folder || $child instanceof Document\Printcontainer) {
             $this->doGetChildren($child);
         }
         if ($child instanceof Document\Hardlink) {
             if ($child->getSourceDocument() instanceof Document\Printpage) {
                 $this->allChildren[] = $child;
             }
             $this->doGetChildren($child);
         }
     }
 }
Example #9
0
 /**
  * @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);
 }
Example #10
0
 public function getDocumentTypesAction()
 {
     $documentTypes = Document::getTypes();
     $typeItems = [];
     foreach ($documentTypes as $documentType) {
         $typeItems[] = ["text" => $documentType];
     }
     $this->_helper->json($typeItems);
 }
Example #11
0
 public function ruleGetAction()
 {
     $target = Targeting\Rule::getById($this->getParam("id"));
     $redirectUrl = $target->getActions()->getRedirectUrl();
     if (is_numeric($redirectUrl)) {
         $doc = Document::getById($redirectUrl);
         if ($doc instanceof Document) {
             $target->getActions()->redirectUrl = $doc->getFullPath();
         }
     }
     $this->_helper->json($target);
 }
Example #12
0
 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);
 }
Example #13
0
 protected function getCondition()
 {
     if ($cond = $this->model->getCondition()) {
         if (Document::doHideUnpublished() && !$this->model->getUnpublished()) {
             return " WHERE (" . $cond . ") AND published = 1";
         }
         return " WHERE " . $cond . " ";
     } elseif (Document::doHideUnpublished() && !$this->model->getUnpublished()) {
         return " WHERE published = 1";
     }
     return "";
 }
 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;
 }
Example #15
0
 /**
  * Loads a list of objects (all are an instance of Document) for the given parameters an return them
  *
  * @return array
  */
 public function load()
 {
     $documents = [];
     $select = (string) $this->getQuery(['id', "type"]);
     $documentsData = $this->db->fetchAll($select, $this->model->getConditionVariables());
     foreach ($documentsData as $documentData) {
         if ($documentData["type"]) {
             if ($doc = Document::getById($documentData["id"])) {
                 $documents[] = $doc;
             }
         }
     }
     $this->model->setDocuments($documents);
     return $documents;
 }
 /**
  * Original function
  * @see Admin_DocumentController::treeGetChildsByIdAction()
  */
 public function treeGetChildsByIdAction()
 {
     $languages = Tool::getValidLanguages();
     $language = $this->_getParam("language", reset($languages));
     $document = Document::getById($this->getParam("node"));
     $documents = array();
     if ($document->hasChilds()) {
         $limit = intval($this->getParam("limit"));
         if (!$this->getParam("limit")) {
             $limit = 100000000;
         }
         $offset = intval($this->getParam("start"));
         $list = new Document\Listing();
         if ($this->getUser()->isAdmin()) {
             $list->setCondition("parentId = ? ", $document->getId());
         } else {
             $userIds = $this->getUser()->getRoles();
             $userIds[] = $this->getUser()->getId();
             $list->setCondition("parentId = ? and\r\n                                        (\r\n                                        (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(path,`key`),cpath)=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\r\n                                        or\r\n                                        (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(path,`key`))=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\r\n                                        )", $document->getId());
         }
         $list->setOrderKey("index");
         $list->setOrder("asc");
         $list->setLimit($limit);
         $list->setOffset($offset);
         $childsList = $list->load();
         foreach ($childsList as $childDocument) {
             // only display document if listing is allowed for the current user
             if ($childDocument->isAllowed("list")) {
                 if ($childDocument instanceof Document\Page && $childDocument->hasProperty('isLanguageRoot') && $childDocument->getProperty('isLanguageRoot') == 1) {
                     if ($childDocument->getKey() == $language) {
                         //                            $documents[] = $this->getTreeNodeConfig($childDocument);
                         $config = $this->getTreeNodeConfig($childDocument);
                         $config['expanded'] = true;
                         $documents[] = $config;
                     }
                 } else {
                     $documents[] = $this->getTreeNodeConfig($childDocument);
                 }
             }
         }
     }
     if ($this->getParam("limit")) {
         $this->_helper->json(array("offset" => $offset, "limit" => $limit, "total" => $document->getChildAmount($this->getUser()), "nodes" => $documents));
     } else {
         $this->_helper->json($documents);
     }
     $this->_helper->json(false);
 }
Example #17
0
 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]);
 }
Example #18
0
 protected function getFilterPath()
 {
     if ($this->getParam("type") == "document" && $this->getParam("id")) {
         $doc = Document::getById($this->getParam("id"));
         $path = $doc->getFullPath();
         if ($doc instanceof Document\Page && $doc->getPrettyUrl()) {
             $path = $doc->getPrettyUrl();
         }
         if ($this->getParam("site")) {
             $site = Site::getById($this->getParam("site"));
             $path = preg_replace("@^" . preg_quote($site->getRootPath(), "@") . "/@", "/", $path);
         }
         return $path;
     }
     return $this->getParam("path");
 }
Example #19
0
 /**
  * @return null
  */
 public function getRenderScript()
 {
     // try to get the template out of the params
     if ($this->getParam("template")) {
         return $this->getParam("template");
     }
     // try to get template out of the document object, but only if the parameter `staticroute´ is not set, which indicates
     // if a request comes through a static/custom route (contains the route Object => Staticroute)
     // see PIMCORE-1545
     if ($this->document instanceof Document && !in_array($this->getParam("pimcore_request_source"), array("staticroute", "renderlet"))) {
         if (method_exists($this->document, "getTemplate") && $this->document->getTemplate()) {
             return $this->document->getTemplate();
         }
     }
     return null;
 }
Example #20
0
 public function testAction()
 {
     /*
      * This is an example of a categorization of controllers
      * you can create folders to structure your controllers into sub-modules
      *
      * The controller name is then the name of the folder and the controller, separated by an underscore (_)
      * in this case this is "category_example"
      *
      * For this example there's a static route and a document defined
      * Name of static route: "category-example"
      * Path of document: /en/advanced-examples/sub-modules
      */
     $this->enableLayout();
     // this is needed so that the layout can be rendered
     $this->setDocument(\Pimcore\Model\Document::getById(1));
 }
Example #21
0
 /**
  * @param $sourceDocument
  * @param $intendedLanguage
  * @return bool|\Pimcore\Model\Document
  */
 public static function getDocumentInOtherLanguage($sourceDocument, $intendedLanguage)
 {
     if ($sourceDocument instanceof \Pimcore\Model\Document) {
         $documentId = $sourceDocument->getId();
     } else {
         $documentId = $sourceDocument;
     }
     $tSource = new Keys();
     $tTarget = new Keys();
     $select = $tSource->select()->from(array("s" => $tSource->info("name")), array())->from(array("t" => $tTarget->info("name")), array("document_id"))->where("s.document_id = ?", $documentId)->where("s.sourcePath = t.sourcePath")->where("t.language = ?", $intendedLanguage);
     $row = $tSource->fetchRow($select);
     if (!empty($row)) {
         return \Pimcore\Model\Document::getById($row->document_id);
     } else {
         return false;
     }
 }
Example #22
0
 /**
  * @param Document $document
  */
 public static function getSiteForDocument($document)
 {
     $cacheKey = "sites_full_list";
     if (\Zend_Registry::isRegistered($cacheKey)) {
         $sites = \Zend_Registry::get($cacheKey);
     } else {
         $sites = new Site\Listing();
         $sites = $sites->load();
         \Zend_Registry::set($cacheKey, $sites);
     }
     foreach ($sites as $site) {
         if (preg_match("@^" . $site->getRootPath() . "/@", $document->getRealFullPath()) || $site->getRootDocument()->getId() == $document->getId()) {
             return $site;
         }
     }
     return;
 }
Example #23
0
 /**
  * @param $id
  * @throws \Exception
  */
 public function getById($id)
 {
     $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id);
     if (!$data["id"]) {
         throw new \Exception("Note item with id " . $id . " not found");
     }
     $this->assignVariablesToModel($data);
     // get key-value data
     $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id);
     $preparedData = array();
     foreach ($keyValues as $keyValue) {
         $data = $keyValue["data"];
         $type = $keyValue["type"];
         $name = $keyValue["name"];
         if ($type == "document") {
             if ($data) {
                 $data = Document::getById($data);
             }
         } else {
             if ($type == "asset") {
                 if ($data) {
                     $data = Asset::getById($data);
                 }
             } else {
                 if ($type == "object") {
                     if ($data) {
                         $data = Object\AbstractObject::getById($data);
                     }
                 } else {
                     if ($type == "date") {
                         if ($data > 0) {
                             $data = new \Zend_Date($data);
                         }
                     } else {
                         if ($type == "bool") {
                             $data = (bool) $data;
                         }
                     }
                 }
             }
         }
         $preparedData[$name] = array("data" => $data, "type" => $type);
     }
     $this->model->setData($preparedData);
 }
Example #24
0
 /**
  * @param $parentId
  * @param $languageToAdd
  */
 protected function addDocuments($parentId, $languageToAdd)
 {
     $list = new Listing();
     $list->setCondition('parentId = ?', $parentId);
     $list = $list->load();
     foreach ($list as $document) {
         // Create new document
         $targetParent = \Pimcore\Model\Document::getById(\Multilingual\Document::getDocumentIdInOtherLanguage($document->getParentId(), $languageToAdd));
         /** @var Document_Page $target */
         $target = clone $document;
         $target->id = null;
         $target->setParent($targetParent);
         // Only sync properties when it is allowed
         if (!$target->hasProperty('doNotSyncProperties') && !$document->hasProperty('doNotSyncProperties')) {
             $editableDocumentTypes = array('page', 'email', 'snippet');
             if (in_array($document->getType(), $editableDocumentTypes)) {
                 $target->setContentMasterDocument($document);
             }
             // Set the properties the same
             $sourceProperties = $document->getProperties();
             /** @var string $key
              * @var Property $value
              */
             foreach ($sourceProperties as $key => $value) {
                 if (!$target->hasProperty($key)) {
                     $propertyValue = $value->getData();
                     if ($value->getType() == 'document') {
                         $propertyValue = \Multilingual\Document::getDocumentIdInOtherLanguage($value->getData()->getId(), $languageToAdd);
                     }
                     $target->setProperty($key, $value->getType(), $propertyValue, false, $value->getInheritable());
                 }
             }
         }
         $target->save();
         // Add Link to other languages
         $t = new Keys();
         $t->insert(array("document_id" => $target->getId(), "language" => $languageToAdd, "sourcePath" => $document->getFullPath()));
         // Check for children
         if (count($document->getChilds()) >= 1) {
             // Add the kids
             $this->addDocuments($document->getId(), $languageToAdd);
         }
     }
 }
Example #25
0
 public function codeAction()
 {
     if ($this->getParam("name")) {
         $url = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . "/qr~-~code/" . $this->getParam("name");
     } else {
         if ($this->getParam("documentId")) {
             $doc = Document::getById($this->getParam("documentId"));
             $url = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . $doc->getFullPath();
         } else {
             if ($this->getParam("url")) {
                 $url = $this->getParam("url");
             }
         }
     }
     $codeSettings = array('text' => $url, 'backgroundColor' => '#FFFFFF', 'foreColor' => '#000000', 'padding' => 0, 'moduleSize' => 10);
     $extension = $this->getParam("renderer");
     if ($extension == "image") {
         $extension = "png";
     }
     $renderSettings = array();
     if ($this->getParam("download")) {
         $renderSettings["sendResult"] = array('Content-Disposition: attachment;filename="qrcode-' . $this->getParam("name") . '.' . $extension . '"');
     }
     foreach ($this->getAllParams() as $key => $value) {
         if (array_key_exists($key, $codeSettings) && !empty($value)) {
             if (stripos($key, "color")) {
                 if (strlen($value) == 7) {
                     $value = strtoupper($value);
                     $codeSettings[$key] = $value;
                 }
             } else {
                 $codeSettings[$key] = $value;
             }
         }
         if (array_key_exists($key, $renderSettings) && !empty($value)) {
             $renderSettings[$key] = $value;
         }
     }
     $renderer = "image";
     if ($this->getParam("renderer") && in_array($this->getParam("renderer"), array("pdf", "image", "eps", "svg"))) {
         $renderer = $this->getParam("renderer");
     }
     $code = \Pimcore\Image\Matrixcode::render('qrcode', $codeSettings, $renderer, $renderSettings);
 }
Example #26
0
 /**
  * @param Model\Tool\Newsletter\Config $newsletter
  * @param Object\Concrete $object
  */
 public static function sendMail($newsletter, $object, $emailAddress = null, $hostUrl = null)
 {
     $params = ["gender" => $object->getGender(), 'firstname' => $object->getFirstname(), 'lastname' => $object->getLastname(), "email" => $object->getEmail(), 'token' => $object->getProperty("token"), "object" => $object];
     $mail = new Mail();
     $mail->setIgnoreDebugMode(true);
     if (\Pimcore\Config::getSystemConfig()->newsletter->usespecific) {
         $mail->init("newsletter");
     }
     if (!Tool::getHostUrl() && $hostUrl) {
         $mail->setHostUrl($hostUrl);
     }
     if ($emailAddress) {
         $mail->addTo($emailAddress);
     } else {
         $mail->addTo($object->getEmail());
     }
     $mail->setDocument(Document::getById($newsletter->getDocument()));
     $mail->setParams($params);
     // render the document and rewrite the links (if analytics is enabled)
     if ($newsletter->getGoogleAnalytics()) {
         if ($content = $mail->getBodyHtmlRendered()) {
             include_once "simple_html_dom.php";
             $html = str_get_html($content);
             if ($html) {
                 $links = $html->find("a");
                 foreach ($links as $link) {
                     if (preg_match("/^(mailto)/", trim(strtolower($link->href)))) {
                         continue;
                     }
                     $glue = "?";
                     if (strpos($link->href, "?")) {
                         $glue = "&";
                     }
                     $link->href = $link->href . $glue . "utm_source=Newsletter&utm_medium=Email&utm_campaign=" . $newsletter->getName();
                 }
                 $content = $html->save();
                 $html->clear();
                 unset($html);
             }
             $mail->setBodyHtml($content);
         }
     }
     $mail->send();
 }
Example #27
0
 public function contactFormAction()
 {
     $success = false;
     if ($this->getParam("provider")) {
         $adapter = Tool\HybridAuth::authenticate($this->getParam("provider"));
         if ($adapter) {
             $user_data = $adapter->getUserProfile();
             if ($user_data) {
                 $this->setParam("firstname", $user_data->firstName);
                 $this->setParam("lastname", $user_data->lastName);
                 $this->setParam("email", $user_data->email);
                 $this->setParam("gender", $user_data->gender);
             }
         }
     }
     // getting parameters is very easy ... just call $this->getParam("yorParamKey"); regardless if's POST or GET
     if ($this->getParam("firstname") && $this->getParam("lastname") && $this->getParam("email") && $this->getParam("message")) {
         $success = true;
         $mail = new Mail();
         $mail->setIgnoreDebugMode(true);
         // To is used from the email document, but can also be set manually here (same for subject, CC, BCC, ...)
         //$mail->addTo("*****@*****.**");
         $emailDocument = $this->document->getProperty("email");
         if (!$emailDocument) {
             $emailDocument = Document::getById(38);
         }
         $mail->setDocument($emailDocument);
         $mail->setParams($this->getAllParams());
         $mail->send();
     }
     // do some validation & assign the parameters to the view
     foreach (["firstname", "lastname", "email", "message", "gender"] as $key) {
         if ($this->getParam($key)) {
             $this->view->{$key} = htmlentities(strip_tags($this->getParam($key)));
         }
     }
     // assign the status to the view
     $this->view->success = $success;
 }
Example #28
0
 /**
  * @param $data
  * @return array
  */
 protected function prepareData($data)
 {
     $mappedData = array();
     // fix htmlentities issues
     $tmpData = array();
     foreach ($data as $d) {
         if ($d["text"] != htmlentities($d["text"], null, "UTF-8")) {
             $td = $d;
             $td["text"] = htmlentities($d["text"], null, "UTF-8");
             $tmpData[] = $td;
         }
         $tmpData[] = $d;
     }
     $data = $tmpData;
     // prepare data
     foreach ($data as $d) {
         if ($d["link"] || $d["abbr"] || $d["acronym"]) {
             $r = $d["text"];
             if ($d["abbr"]) {
                 $r = '<abbr class="pimcore_glossary" title="' . $d["abbr"] . '">' . $r . '</abbr>';
             } else {
                 if ($d["acronym"]) {
                     $r = '<acronym class="pimcore_glossary" title="' . $d["acronym"] . '">' . $r . '</acronym>';
                 }
             }
             $linkType = "";
             $linkTarget = "";
             if ($d["link"]) {
                 $linkType = "external";
                 $linkTarget = $d["link"];
                 if (intval($d["link"])) {
                     if ($doc = Model\Document::getById($d["link"])) {
                         $d["link"] = $doc->getFullPath();
                         $linkType = "internal";
                         $linkTarget = $doc->getId();
                     }
                 }
                 $r = '<a class="pimcore_glossary" href="' . $d["link"] . '">' . $r . '</a>';
             }
             // add PCRE delimiter and modifiers
             if ($d["exactmatch"]) {
                 $d["text"] = "/(?<!\\w)" . preg_quote($d["text"], "/") . "(?!\\w)/";
             } else {
                 $d["text"] = "/" . preg_quote($d["text"], "/") . "/";
             }
             if (!$d["casesensitive"]) {
                 $d["text"] .= "i";
             }
             $mappedData[] = array("replace" => $r, "search" => $d["text"], "linkType" => $linkType, "linkTarget" => $linkTarget);
         }
     }
     return $mappedData;
 }
Example #29
0
 /**
  * @param $wsDocument
  * @throws \Exception
  */
 protected function updateDocument($wsDocument)
 {
     $document = Document::getById($wsDocument->id);
     if ($document === NULL) {
         throw new \Exception("Document with given ID (" . $wsDocument->id . ") does not exist.");
     }
     $this->setModificationParams($document, false);
     if ($document instanceof Document and strtolower($wsDocument->type) == $document->getType()) {
         $wsDocument->reverseMap($document);
         $document->save();
         return true;
     } else {
         throw new \Exception("Type mismatch for given document with ID [" . $wsDocument->id . "] and existing document with id [" . $document->getId() . "]");
     }
 }
Example #30
0
 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();
     }
 }