Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Format Message with Attributes
- * @var mixed $contact
- * @var string message
- */
- public function formatMessageWithAttributes($contact, &$message) {
- $data = array_merge(empty($contact->data) ? [] : $contact->data, [
- 'name' => $contact->name,
- 'phone' => $contact->phone
- ]);
- preg_match_all('/{(.*?)}/', $message, $matches);
- foreach($matches[1] as $match)
- {
- // Explode to get key and default value
- $parts = explode('|', $match);
- // Get the key and default value
- $key = $parts[0];
- $defaultValue = isset($parts[1]) ? $parts[1] : '';
- // Get the replacement value, with default fallback
- $value = array_key_exists($key, $data) ? $data[$key] : $defaultValue;
- // Replace the occurrences of this with the match
- // DON'T put the curly braces in the same string as match, php will think it's part of the variable string injection
- $message = str_replace("{".$match."}", $value, $message);
- }
- }
- /**
- * Format Message With Vanity URL
- * Example, Https://www.blaxtr.com or https://blaxtr.com
- * @var string messages
- */
- public function formatMessagesWithVanityUrlsFromWholeDomains($contact, &$message) {
- // Create Contact Vanity Urls
- preg_match_all('/(\b(https?|http?):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i', $message, $vanityHttpMatches);
- foreach($vanityHttpMatches as $m => $match) {
- foreach($match as $ke => $value) {
- if(in_array($value, ['https', 'http'])) {
- continue;
- }
- $_match = $value;
- $urlReplace = preg_quote(addslashes($value));
- $urlReplace = preg_replace('/\//', '\\/',$urlReplace);
- try {
- $vanityUrl = $this->generateVanityUrl($this->campaign->id, $_match, $contact->id, $this->broadcast->id, $this->broadcast->proc_id);
- $message = preg_replace('/'.$urlReplace.'/i', $vanityUrl, $message);
- } catch(\Exception $e) {
- }
- }
- }
- }
- public function formatMessageWithVanityUrlFromHostname($contact, &$message) {
- preg_match_all('/([a-z0-9][a-z0-9\-]{0,61}[a-z0-9]\.)+[a-z0-9][a-z0-9\-]*[a-z0-9]/i', $message, $vanityNoHttpMatches);
- foreach($vanityNoHttpMatches as $m => $match) {
- foreach($match as $k => $potentialUrl) {
- if(in_array($potentialUrl, ['wwr.link'])) {
- continue;
- }
- if($this->urlExists('https://'.$potentialUrl)) {
- $vanityUrl = $this->generateVanityUrl($this->campaign->id, 'https://'.$potentialUrl, $contact->id, $this->broadcast->id, $this->broadcast->proc_id);
- $urlReplace = preg_quote(addslashes($potentialUrl));
- $urlReplace = preg_replace('/\//', '\\/',$urlReplace);
- $message = preg_replace('/'.$urlReplace.'/i', $vanityUrl, $message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement