data = new Diff($previousData, $currentData); } public function send() { if (!($updatedData = $this->data->getDiff())) { return false; } $subject = SettingsObj::get('changeProfileEmailSubject'); $from = SettingsObj::getEmailFrom('changeProfileEmailFrom'); $to = SettingsObj::getFormEmails('changeProfileEmailTo'); $body = SettingsObj::get('changeProfileEmailBody'); $data = $this->data->getData2(); $data['link'] = BASE_URL_LANGUAGE; if (false !== ($link = Qs_SiteMap::findFirst(null, ['type' => 'User\\Admin\\'], null, 'url'))) { $query = ['action' => 'edit', 'id' => $data['id']]; $data['link'] = $link . '?' . http_build_query($query); } $data['changedFields'] = $this->_renderChangedFields($updatedData); $escapedFields = ['changedFields']; foreach ($data as $field => $value) { if (is_array($value)) { continue; } if (!in_array($field, $escapedFields)) { $value = htmlspecialchars($value); } $body = str_replace('{' . $field . '}', $value, $body); } return $this->_sendMail(compact('subject', 'from', 'to', 'body')); } protected function _renderChangedFields(array $data) { /** @var \Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); $smarty = $doc->getSmarty(); $smarty->assign('DOC', $doc); $item['fields'] = $data; $smarty->assign('item', new Qs_Doc_Item($item)); return $smarty->fetch('User/changed-fields-render.tpl'); } protected function _sendMail($options) { $requiredOptions = ['from', 'to', 'subject', 'body']; $diff = array_diff_key(array_combine($requiredOptions, array_fill(0, count($requiredOptions), '')), $options); if (!empty($diff)) { throw new Exception('Missed required options: ' . implode(', ', array_keys($diff))); } $from = $to = $subject = $body = ''; $attachments = []; extract($options); $mail = new Qs_Mail(); $mail->setFrom($from); $mail->setSubject($subject); foreach ($attachments as $attachment) { $mail->attachFile($attachment); } Qs_Mail::cutImageBaseUrl($body, constant('BASE_URL')); $mail->setHtml($body, null, constant('WWW_PATH')); $mail->addTo($to); return $mail->send(); } }