Make is_archived work as a url-search parameter
[civicrm-core.git] / CRM / Mailing / Page / Preview.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * a page for mailing preview
20 */
21 class CRM_Mailing_Page_Preview extends CRM_Core_Page {
22
23 /**
24 * Run this page (figure out the action needed and perform it).
25 */
26 public function run() {
27
28 $session = CRM_Core_Session::singleton();
29
30 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
31 $type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
32
33 $options = [];
34 $session->getVars($options, "CRM_Mailing_Controller_Send_$qfKey");
35
36 // get the options if control come from search context, CRM-3711
37 if (empty($options)) {
38 $session->getVars($options, "CRM_Contact_Controller_Search_$qfKey");
39 }
40
41 // FIXME: the below and CRM_Mailing_Form_Test::testMail()
42 // should be refactored
43 $fromEmail = NULL;
44 $mailing = new CRM_Mailing_BAO_Mailing();
45 if (!empty($options)) {
46 $mailing->id = $options['mailing_id'];
47 $fromEmail = $options['from_email'] ?? NULL;
48 }
49
50 $mailing->find(TRUE);
51
52 CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
53
54 // get and format attachments
55 $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing',
56 $mailing->id
57 );
58
59 // get details of contact with token value including Custom Field Token Values.CRM-3734
60 $returnProperties = $mailing->getReturnProperties();
61 $params = ['contact_id' => $session->get('userID')];
62
63 $details = CRM_Utils_Token::getTokenDetails($params,
64 $returnProperties,
65 TRUE, TRUE, NULL,
66 $mailing->getFlattenedTokens(),
67 get_class($this)
68 );
69 // $details[0] is an array of [ contactID => contactDetails ]
70 $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail,
71 TRUE, $details[0][$session->get('userID')], $attachments
72 );
73
74 if ($type == 'html') {
75 CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
76 print $mime->getHTMLBody();
77 }
78 else {
79 CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
80 print $mime->getTXTBody();
81 }
82 CRM_Utils_System::civiExit();
83 }
84
85 }