BxMassMailerFormEntry.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup MassMailer Mass Mailer
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxMassMailerFormCheckerHelper extends BxDolFormCheckerHelper
  12. {
  13. static public function checkEmailOrEmpty($s)
  14. {
  15. if (trim($s) == '')
  16. return true;
  17. if (!self::checkEmail($s))
  18. return false;
  19. return true;
  20. }
  21. static public function checkUnsubscribeUrl($s)
  22. {
  23. if (trim($s) == '')
  24. return false;
  25. if (strpos($s, '{unsubscribe_url}') === false)
  26. return false;
  27. return true;
  28. }
  29. }
  30. /**
  31. * Create/Edit entry form
  32. */
  33. class BxMassMailerFormEntry extends BxBaseModTextFormEntry
  34. {
  35. protected $_bCreative;
  36. public function __construct($aInfo, $oTemplate = false)
  37. {
  38. $this->MODULE = 'bx_massmailer';
  39. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  40. parent::__construct($aInfo, $oTemplate);
  41. $CNF = &$this->_oModule->_oConfig->CNF;
  42. $this->_bCreative = $CNF['PARAM_USE_CREATIVE'];
  43. if (isset( $this->aInputs[$CNF['FIELD_SEGMENTS']]))
  44. $this->aInputs[$CNF['FIELD_SEGMENTS']]['values'] = $this->_oModule->getSegments();
  45. }
  46. public function getCode($bDynamicMode = false)
  47. {
  48. $sResult = parent::getCode($bDynamicMode);
  49. $this->_oModule->_oTemplate->addJs([
  50. 'grapesjs/grapes.min.js',
  51. 'grapesjs/grapesjs-preset-newsletter.min.js'
  52. ]);
  53. $this->_oModule->_oTemplate->addCss([
  54. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css'
  55. ]);
  56. return $sResult;
  57. }
  58. public function initChecker ($aValues = [], $aSpecificValues = [])
  59. {
  60. $CNF = &$this->_oModule->_oConfig->CNF;
  61. $bValues = $aValues && !empty($aValues['id']);
  62. $iCampaignId = $bValues ? (int)$aValues['id'] : 0;
  63. $aCampaignInfo = $bValues ? $this->_oModule->_oDb->getCampaignInfoById($aValues['id']) : false;
  64. if($this->_bCreative && isset($this->aInputs[$CNF['FIELD_BODY']])) {
  65. $sContent = !empty($aCampaignInfo['body']) ? $aCampaignInfo['body'] : '';
  66. if(!$this->_bIsApi)
  67. $this->aInputs[$CNF['FIELD_BODY']] = array_merge($this->aInputs[$CNF['FIELD_BODY']], [
  68. 'type' => 'custom',
  69. 'content' => $this->_oModule->_oTemplate->parseHtmlByName('campaign_body.html', [
  70. 'name' => $this->aInputs[$CNF['FIELD_BODY']]['name'],
  71. 'html_id' => $this->_oModule->_oConfig->getHtmlIds('campaign_body'),
  72. 'content_html' => $sContent,
  73. 'content_data' => json_encode([
  74. 'pages' => [
  75. ['component' => $sContent]
  76. ]
  77. ])
  78. ]),
  79. ]);
  80. else
  81. $this->aInputs[$CNF['FIELD_BODY_INFO']] = array_merge($this->aInputs[$CNF['FIELD_BODY_INFO']], [
  82. 'type' => 'value',
  83. 'value' => $this->_oModule->serviceAttributes()
  84. ]);
  85. }
  86. parent::initChecker ($aValues, $aSpecificValues);
  87. }
  88. public function insert ($aValsToAdd = array(), $isIgnore = false)
  89. {
  90. $CNF = &$this->_oModule->_oConfig->CNF;
  91. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id();
  92. return parent::insert ($aValsToAdd, $isIgnore);
  93. }
  94. protected function genCustomInputBodyInfo ($aInput)
  95. {
  96. return $this->_oModule->serviceAttributes();
  97. }
  98. }
  99. /** @} */