All Data Structures Functions Variables Pages
MergeTagsContentResolverUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  const ADD_GLOBAL_FOOTER_MERGE_TAGS_IF_MISSING = 1;
40 
41  const REMOVE_GLOBAL_FOOTER_MERGE_TAGS_IF_PRESENT = -1;
42 
60  public static function resolveContentsForGlobalFooterAndMergeTagsAndTracking(& $textContent, & $htmlContent,
61  RedBeanModel $attachedModel = null, $emailTemplateType = EmailTemplate::TYPE_CONTACT,
62  $errorOnFirstMissing = MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG,
63  $language = null, array & $invalidTags = array(), $marketingListId = null,
64  $preview = false, $addGlobalFooterMergeTags = self::ADD_GLOBAL_FOOTER_MERGE_TAGS_IF_MISSING,
65  $enableTracking = true, $modelId = null, $modelType = null, $personId = null)
66  {
67  assert('($textContent === null) || is_string($textContent)');
68  assert('($htmlContent === null) || is_string($htmlContent)');
69  assert('($attachedModel === null) || is_object($attachedModel)');
70  assert('is_int($emailTemplateType)');
71  assert('in_array($emailTemplateType, array_keys(EmailTemplate::getTypeDropDownArray()))');
72  assert('is_int($errorOnFirstMissing)');
73  assert('($language === null) || is_string($language)');
74  assert('is_array($invalidTags)');
75  assert('($marketingListId === null) || is_int($marketingListId)');
76  assert('is_bool($preview)');
77  assert('is_int($addGlobalFooterMergeTags)');
78  assert('is_bool($enableTracking)');
79  assert('($modelId === null) || is_int($modelId)');
80  assert('($modelType === null) || is_string($modelType)');
81  assert('($personId === null) || is_int($personId)');
82  static::resolveContentsForGlobalFooterMergeTags($textContent, $htmlContent, $addGlobalFooterMergeTags);
83  static::resolveContentsForMergeTags($textContent, $htmlContent, $attachedModel, $emailTemplateType,
84  $errorOnFirstMissing, $language, $invalidTags, $marketingListId,
85  $preview, $modelId, $modelType, $personId);
86  static::resolveContentsForTracking($textContent, $htmlContent, $enableTracking, $modelId, $modelType, $personId);
87  }
88 
95  public static function resolveContentsForGlobalFooterMergeTags(& $textContent, & $htmlContent,
96  $addGlobalFooterMergeTags = self::ADD_GLOBAL_FOOTER_MERGE_TAGS_IF_MISSING)
97  {
98  if ($addGlobalFooterMergeTags == static::ADD_GLOBAL_FOOTER_MERGE_TAGS_IF_MISSING)
99  {
100  GlobalMarketingFooterUtil::resolveContentsForGlobalFooter($textContent, $htmlContent);
101  }
102  else
103  {
104  static::removeGlobalFooterMergeTagsFromContents($textContent, $htmlContent);
105  }
106  }
107 
113  public static function removeGlobalFooterMergeTagsFromContents(& $textContent, & $htmlContent)
114  {
115  GlobalMarketingFooterUtil::removeFooterMergeTags($textContent);
116  GlobalMarketingFooterUtil::removeFooterMergeTags($htmlContent);
117  }
118 
119  public static function resolveContentsForTracking(& $textContent, & $htmlContent, $enableTracking = true,
120  $modelId = null, $modelType = null, $personId = null)
121  {
122  if ($enableTracking)
123  {
124  ContentTrackingUtil::resolveContentsForTracking($textContent, $htmlContent, $enableTracking,
125  $modelId, $modelType, $personId);
126  }
127  }
128 
145  public static function resolveContentsForMergeTags(& $textContent, & $htmlContent, RedBeanModel $attachedModel = null,
146  $emailTemplateType = EmailTemplate::TYPE_CONTACT,
147  $errorOnFirstMissing = MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG,
148  $language = null, array & $invalidTags = array(),
149  $marketingListId = null, $preview = false, $modelId = null,
150  $modelType = null, $personId = null)
151  {
152  static::resolveContentForMergeTagsWithExceptionOnFailure($textContent, $attachedModel, $emailTemplateType,
153  $errorOnFirstMissing, $language, $invalidTags,
154  $marketingListId, $preview, $modelId,
155  $modelType, $personId, false);
156  static::resolveContentForMergeTagsWithExceptionOnFailure($htmlContent, $attachedModel, $emailTemplateType,
157  $errorOnFirstMissing, $language, $invalidTags,
158  $marketingListId, $preview, $modelId,
159  $modelType, $personId, true);
160  }
161 
178  public static function resolveContentForMergeTagsWithExceptionOnFailure(& $content, RedBeanModel $attachedModel = null,
179  $emailTemplateType = EmailTemplate::TYPE_CONTACT,
180  $errorOnFirstMissing = MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG,
181  $language = null, array & $invalidTags = array(),
182  $marketingListId = null, $preview = false, $modelId = null,
183  $modelType = null, $personId = null, $isHtmlContent = false)
184  {
185  $resolved = static::resolveContentForMergeTags($content, $attachedModel, $emailTemplateType, $errorOnFirstMissing,
186  $language, $invalidTags, $marketingListId, $preview, $modelId,
187  $modelType, $personId, $isHtmlContent);
188  if ($resolved === false)
189  {
190  throw new NotSupportedException(Zurmo::t('EmailTemplatesModule', 'Provided content contains few invalid merge tags.'));
191  }
192  }
193 
211  public static function resolveContentForMergeTags(& $content, RedBeanModel $attachedModel = null,
212  $emailTemplateType = EmailTemplate::TYPE_CONTACT,
213  $errorOnFirstMissing = MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG,
214  $language = null, array & $invalidTags = array(),
215  $marketingListId = null, $preview = false, $modelId = null,
216  $modelType = null, $personId = null, $isHtmlContent = false)
217  {
218  $params = GlobalMarketingFooterUtil::resolveFooterMergeTagsArray($personId, $marketingListId,
219  $modelId, $modelType, !$preview,
220  $preview, $isHtmlContent);
221  $util = MergeTagsUtilFactory::make($emailTemplateType, $language, $content);
222  $resolvedContent = $util->resolveMergeTags($attachedModel, $invalidTags, $language, $errorOnFirstMissing, $params, false, $modelId, $modelType, $isHtmlContent);
223  if ($resolvedContent !== false)
224  {
225  $content = $resolvedContent;
226  return true;
227  }
228  return false;
229  }
230  }
231 ?>
static resolveContentsForGlobalFooterAndMergeTagsAndTracking(&$textContent, &$htmlContent, RedBeanModel $attachedModel=null, $emailTemplateType=EmailTemplate::TYPE_CONTACT, $errorOnFirstMissing=MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG, $language=null, array &$invalidTags=array(), $marketingListId=null, $preview=false, $addGlobalFooterMergeTags=self::ADD_GLOBAL_FOOTER_MERGE_TAGS_IF_MISSING, $enableTracking=true, $modelId=null, $modelType=null, $personId=null)
static resolveContentForMergeTags(&$content, RedBeanModel $attachedModel=null, $emailTemplateType=EmailTemplate::TYPE_CONTACT, $errorOnFirstMissing=MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG, $language=null, array &$invalidTags=array(), $marketingListId=null, $preview=false, $modelId=null, $modelType=null, $personId=null, $isHtmlContent=false)
static make($emailTemplateType, $language, $content)
static resolveContentsForMergeTags(&$textContent, &$htmlContent, RedBeanModel $attachedModel=null, $emailTemplateType=EmailTemplate::TYPE_CONTACT, $errorOnFirstMissing=MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG, $language=null, array &$invalidTags=array(), $marketingListId=null, $preview=false, $modelId=null, $modelType=null, $personId=null)
static removeGlobalFooterMergeTagsFromContents(&$textContent, &$htmlContent)
static resolveContentForMergeTagsWithExceptionOnFailure(&$content, RedBeanModel $attachedModel=null, $emailTemplateType=EmailTemplate::TYPE_CONTACT, $errorOnFirstMissing=MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG, $language=null, array &$invalidTags=array(), $marketingListId=null, $preview=false, $modelId=null, $modelType=null, $personId=null, $isHtmlContent=false)
static resolveContentsForGlobalFooterMergeTags(&$textContent, &$htmlContent, $addGlobalFooterMergeTags=self::ADD_GLOBAL_FOOTER_MERGE_TAGS_IF_MISSING)
Generated on Wed Feb 26 2020 07:10:38