/**
  * replaceTagContent
  * This is used to replace the place holder for the email to the correct content
  *
  * @param EventData_IEM_ADDON_DYNAMICCONTENTTAGS_REPLACETAGCONTENT $data This will be set and used by the caller function
  * @return void This will return the variable via $data instead of return via function
  */
 public static function replaceTagContent(EventData_IEM_ADDON_DYNAMICCONTENTTAGS_REPLACETAGCONTENT $data)
 {
     require_once SENDSTUDIO_API_DIRECTORY . '/subscribers.php';
     $subsrciberApi = new Subscribers_API();
     $subscriberInfo = $data->info;
     //if there's no data then there's no point in finishing
     if (empty($subscriberInfo) || empty($subscriberInfo[0])) {
         return;
     }
     foreach ($subscriberInfo as $subscriberInfoEntry) {
         if (empty($subscriberInfoEntry) || empty($subscriberInfoEntry['emailaddress']) || empty($subscriberInfoEntry['subscriberid'])) {
             continue;
         }
         $tagObject = new Addons_dynamiccontenttags();
         $subscriberList = $subsrciberApi->GetAllListsForEmailAddress($subscriberInfoEntry['emailaddress'], $data->lists);
         if (is_array($subscriberList)) {
             foreach ($subscriberList as $listKey => $listVal) {
                 $subscriberList[$listKey] = $listVal['listid'];
             }
         } else {
             $subscriberList = array($subscriberList);
         }
         // preload the array key value and customfield id
         $preloadCustomFieldLoc = array();
         if (is_array($subscriberInfoEntry['CustomFields'])) {
             foreach ($subscriberInfoEntry['CustomFields'] as $customFieldKey => $customFieldVal) {
                 $preloadCustomFieldLoc[$customFieldVal['fieldid']] = $customFieldKey;
             }
         }
         $tagObject->loadTagsByList($subscriberList);
         if ($tagObject->getTagObjectsSize()) {
             $tagsTobeReplaced = array();
             $tagsContentTobeReplaced = array();
             $permanentRulesMatches = array('email' => 'emailaddress', 'format' => 'format', 'confirmation' => 'confirmed', 'subscribe' => 'subscribedate');
             $generatedContent = '';
             //stores the content blocks that will be used in this tag, initializing for scope
             foreach ($tagObject->tags as $tagEntry) {
                 $tagEntry->loadBlocks();
                 $blocks = $tagEntry->getBlocks();
                 $defaultBlock = null;
                 $anyRulesPassed = false;
                 foreach ($blocks as $blockEntry) {
                     $rulesPassed = true;
                     $decodedRules = $blockEntry->getDecodedRules();
                     foreach ($decodedRules->Rules[0]->rules as $ruleEntry) {
                         $continue = false;
                         $tempRuleValues = trim(strtolower($ruleEntry->rules->ruleValues));
                         $tempActualValues = isset($permanentRulesMatches[$ruleEntry->rules->ruleName]) && isset($subscriberInfoEntry[$permanentRulesMatches[$ruleEntry->rules->ruleName]]) ? trim(strtolower($subscriberInfoEntry[$permanentRulesMatches[$ruleEntry->rules->ruleName]])) : '';
                         switch ($ruleEntry->rules->ruleName) {
                             case 'email':
                             case 'format':
                             case 'confirmation':
                                 $continue = true;
                                 break;
                             case 'status':
                                 $tempActualValues = array();
                                 $tempIndex = '';
                                 switch ($tempRuleValues) {
                                     case 'a':
                                         $tempIndex = 'notboth';
                                         break;
                                     case 'b':
                                         $tempIndex = 'bounced';
                                         break;
                                     case 'u':
                                         $tempIndex = 'unsubscribed';
                                         break;
                                 }
                                 switch ($ruleEntry->rules->ruleOperator) {
                                     case 'equalto':
                                         if (isset($subscriberInfoEntry[$tempIndex]) && $subscriberInfoEntry[$tempIndex] == 0) {
                                             $rulesPassed = false;
                                         } elseif (!isset($subscriberInfoEntry[$tempIndex]) && !($subscriberInfoEntry['bounced'] == 0 && $subscriberInfoEntry['unsubscribed'] == 0)) {
                                             $rulesPassed = false;
                                         }
                                         break;
                                     case 'notequalto':
                                         if (isset($subscriberInfoEntry[$tempIndex]) && !($subscriberInfoEntry[$tempIndex] == 0)) {
                                             $rulesPassed = false;
                                         } elseif (!isset($subscriberInfoEntry[$tempIndex]) && ($subscriberInfoEntry['bounced'] == 0 && $subscriberInfoEntry['unsubscribed'] == 0)) {
                                             $rulesPassed = false;
                                         }
                                         break;
                                 }
                                 break;
                             case 'subscribe':
                                 // date conversion
                                 $tempActualValues = strtotime(date('Y-m-d', $tempActualValues));
                                 $tempRuleValues = explode('/', $tempRuleValues);
                                 $tempRuleValues = strtotime(implode('-', array_reverse($tempRuleValues)));
                                 $continue = true;
                                 break;
                             case 'campaign':
                                 switch ($ruleEntry->rules->ruleOperator) {
                                     case 'equalto':
                                         if (!$subsrciberApi->IsSubscriberHasOpenedNewsletters($subscriberInfoEntry['emailaddress'], $tempRuleValues)) {
                                             $rulesPassed = false;
                                         }
                                         break;
                                     case 'notequalto':
                                         if ($subsrciberApi->IsSubscriberHasOpenedNewsletters($subscriberInfoEntry['emailaddress'], $tempRuleValues)) {
                                             $rulesPassed = false;
                                         }
                                         break;
                                 }
                                 break;
                             default:
                                 $continue = true;
                         }
                         if ($continue) {
                             if ((int) $ruleEntry->rules->ruleName) {
                                 $tempActualValues = isset($preloadCustomFieldLoc[$ruleEntry->rules->ruleName]) && isset($subscriberInfoEntry['CustomFields'][$preloadCustomFieldLoc[$ruleEntry->rules->ruleName]]['data']) ? trim(strtolower($subscriberInfoEntry['CustomFields'][$preloadCustomFieldLoc[$ruleEntry->rules->ruleName]]['data'])) : '';
                                 if ($ruleEntry->rules->ruleType == 'date') {
                                     $tempActualValues = split('/', $tempActualValues);
                                     $tempActualValues = strtotime(implode('-', array_reverse($tempActualValues)));
                                     $tempRuleValues = split('/', $tempRuleValues);
                                     $tempRuleValues = strtotime(implode('-', array_reverse($tempRuleValues)));
                                 }
                             }
                             switch ($ruleEntry->rules->ruleType) {
                                 case 'text':
                                 case 'textarea':
                                 case 'dropdown':
                                 case 'number':
                                 case 'radiobutton':
                                 case 'date':
                                     switch ($ruleEntry->rules->ruleOperator) {
                                         case 'equalto':
                                             if (!($tempActualValues == $tempRuleValues)) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         case 'notequalto':
                                             if ($tempActualValues == $tempRuleValues) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         case 'like':
                                             if (!strstr($tempActualValues, $tempRuleValues)) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         case 'notlike':
                                             if (strstr($tempActualValues, $tempRuleValues)) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         case 'greaterthan':
                                             if ($tempActualValues <= $tempRuleValues) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         case 'lessthan':
                                             if ($tempActualValues >= $tempRuleValues) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         default:
                                             $rulesPassed = false;
                                     }
                                     break;
                                 case 'checkbox':
                                     $tempActualValues = unserialize($tempActualValues);
                                     $tempRuleValues = explode(', ', $tempRuleValues);
                                     $tempRuleValues = is_array($tempRuleValues) ? $tempRuleValues : array();
                                     $tempActualValues = is_array($tempActualValues) ? $tempActualValues : array();
                                     switch ($ruleEntry->rules->ruleOperator) {
                                         case 'equalto':
                                             if (sizeof(array_intersect($tempActualValues, $tempRuleValues)) != sizeof($tempRuleValues)) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         case 'notequalto':
                                             if (sizeof(array_intersect($tempActualValues, $tempRuleValues)) == sizeof($tempRuleValues)) {
                                                 $rulesPassed = false;
                                             }
                                             break;
                                         default:
                                             $rulesPassed = false;
                                     }
                                     break;
                                 default:
                                     $rulesPassed = false;
                             }
                         }
                     }
                     if ($blockEntry->isActivated()) {
                         $defaultBlock = $decodedRules;
                     }
                     if ($rulesPassed && !$blockEntry->isActivated()) {
                         $generatedContent = empty($generatedContent) ? '' : "{$generatedContent}<br />\r\n";
                         $generatedContent .= $decodedRules->Content;
                         $anyRulesPassed = true;
                     }
                 }
                 $data->contentTobeReplaced[$subscriberInfoEntry['subscriberid']]['tagsTobeReplaced'][] = '%%[' . trim($tagEntry->getName()) . ']%%';
                 if ($anyRulesPassed) {
                     $data->contentTobeReplaced[$subscriberInfoEntry['subscriberid']]['tagsContentTobeReplaced'][] = $generatedContent;
                 } else {
                     $data->contentTobeReplaced[$subscriberInfoEntry['subscriberid']]['tagsContentTobeReplaced'][] = $defaultBlock->Content;
                 }
                 $generatedContent = '';
             }
         }
     }
 }
Exemplo n.º 2
0
	/**
	 * _getSubscriberIDSFromList
	 * Get all subsriber IDs with the same email address within a list
	 *
	 * @param Integer $subscriberid Subscriber ID
	 * @param Array $lists An array of list IDs
	 *
	 * @return Array|FALSE an array of return records that can be used to pass through Api::AddToQueue(), FALSE otherwise
	 */
	private function _getSubscriberIDSFromList($subscriberid, $lists)
	{
		if (!is_array($lists) || empty($lists)) {
			return array(array('subscriberid' => $subscriberid));
		}

		require_once(dirname(__FILE__) . '/subscribers.php');
		$subscribersapi = new Subscribers_API();

		$emailaddress = $subscribersapi->GetEmailForSubscriber($subscriberid);
		if (!$emailaddress) {
			return array(array('subscriberid' => $subscriberid));
		}

		$records = $subscribersapi->GetAllListsForEmailAddress($emailaddress, $lists);

		if (empty($records)) {
			return array(array('subscriberid' => $subscriberid));
		}

		return $records;
	}