copyright and version fixes
[civicrm-core.git] / CRM / Mailing / Page / View.php
index 59305426d27a16e3dddcb3f500bdfb0e77f1a1d3..ea0198dad3c016a84850710701984039f98ac6d0 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -75,7 +75,7 @@ class CRM_Mailing_Page_View extends CRM_Core_Page {
    *
    * @return void
    */
-  function run($id = NULL, $contact_id = NULL, $print = TRUE) {
+  function run($id = NULL, $contactID = NULL, $print = TRUE) {
     if (is_numeric($id)) {
       $this->_mailingID = $id;
     }
@@ -117,35 +117,55 @@ class CRM_Mailing_Page_View extends CRM_Core_Page {
     if (isset($this->_contactID)) {
       //get details of contact with token value including Custom Field Token Values.CRM-3734
       $returnProperties = $this->_mailing->getReturnProperties();
-      $params           = array('contact_id' => $this->_contactID);
-      $details          = CRM_Utils_Token::getTokenDetails($params,
+      $params = array('contact_id' => $this->_contactID);
+      $details = CRM_Utils_Token::getTokenDetails($params,
         $returnProperties,
-        TRUE, TRUE, NULL,
+        FALSE, TRUE, NULL,
         $this->_mailing->getFlattenedTokens(),
         get_class($this)
       );
       $details = $details[0][$this->_contactID];
+      $contactId = $this->_contactID;
     }
     else {
-      $details = array('test');
+      //get tokens that are not contact specific resolved
+      $params  = array('contact_id' => 0);
+      $details = CRM_Utils_Token::getAnonymousTokenDetails($params,
+        $returnProperties,
+        TRUE, TRUE, NULL,
+        $this->_mailing->getFlattenedTokens(),
+        get_class($this)
+      );
+
+      $details = $details[0][0];
+      $contactId = 0;
     }
-    $mime = &$this->_mailing->compose(NULL, NULL, NULL, 0,
+    $mime = &$this->_mailing->compose(NULL, NULL, NULL, $contactId,
       $this->_mailing->from_email,
       $this->_mailing->from_email,
       TRUE, $details, $attachments
     );
 
-    if (isset($this->_mailing->body_html)) {
+    $title = NULL;
+    if (isset($this->_mailing->body_html) && empty($_GET['text'])) {
       $header = 'Content-Type: text/html; charset=utf-8';
       $content = $mime->getHTMLBody();
+      if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) {
+        $title = '<head><title>' . $this->_mailing->subject . '</title></head>';
+      }
     }
     else {
       $header = 'Content-Type: text/plain; charset=utf-8';
       $content = $mime->getTXTBody();
     }
+    CRM_Utils_System::setTitle($this->_mailing->subject);
 
+    if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
+      CRM_Core_Page_AJAX::returnJsonResponse($content);
+    }
     if ($print) {
       header($header);
+      print $title;
       print $content;
       CRM_Utils_System::civiExit();
     }