/** * Gets the ACTUAL full domain of the target page. * * When using isolated subdomain and shared ssl, $_GET['r_domain'] contains the original * subdomain and should be used when doing any domain checking. * * @return string The full domain name. */ public static function cache_passeddomain() { $domain = $_SERVER['SERVER_NAME']; if (is::existset($_SERVER, 'QUERY_STRING')) { parse_str($_SERVER['QUERY_STRING'], $sqs); if (is::existset($sqs, 'r_domain')) { $domain = sprintf('%s.%s', $sqs['r_domain'], get::domain($domain)); } } return $domain; }
private function generateEmail(array $args) { if (count($args) < 1 || count($args) > 8) { throw new Exception('Wrong parameter count'); } $ord = array(1 => 'First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth'); $params = array('template' => null, 'to' => null, 'cc' => null, 'bcc' => null, 'subject' => null, 'message' => null, 'params' => null, 'prefix' => null, 'suffix' => null); $pkeys = array_keys($params); $argsC = $args; while (count($pkeys) > 0 && count($argsC) > 0) { $param = array_shift($pkeys); $arg = array_shift($argsC); if ($param == 'template') { if (!is_string($arg) || is::email($arg, true)) { $param = array_shift($pkeys); } elseif (is_string($arg)) { $params['template'] = $arg; } else { throw new InvalidArgumentException('First parameter expected to be a template or email address.'); } } if (in_array($param, array('to', 'cc', 'bcc'))) { if (isset($arg) && is_string($arg) && $arg != '') { if ($eml = is::email($arg, true)) { $params[$param] = $eml; } elseif ($param == 'to') { throw new InvalidArgumentException(sprintf('%s parameter expected to be the recipients email address (1).', $this->ord($pkeys, $params['template']))); } else { while ($param != 'subject') { $param = array_shift($pkeys); } } } elseif (is_array($arg)) { if ($eml = $this->getEmailAddressArray($arg)) { $params[$param] = $eml; } elseif ($param == 'to') { throw new InvalidArgumentException(sprintf('%s parameter expected to be the recipients email address (2).', $this->ord($pkeys, $params['template']))); } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be the subject or an email address.', $this->ord($pkeys, $params['template']))); } } elseif (is::of_class($arg, 'emailAddressList')) { $params[$param] = $arg; } } if ($param == 'subject') { if (is_string($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be the subject.', $this->ord($pkeys, $params['template']))); } } if ($params['template']) { if ($param == 'message') { $param = array_shift($pkeys); } if ($param == 'params') { if (is_array($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be an array of values for the template.', $this->ord($pkeys, $params['template']))); } } elseif (in_array($param, array('prefix', 'suffix'))) { if (!isset($arg)) { $params[$param] = ''; } elseif (is_string($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be a %s string.', $this->ord($pkeys, $params['template']) . $param)); } } } elseif ($param == 'message') { if (is_string($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be the %s string.', $this->ord($pkeys, $params['template']) . $param)); } } } if ($params['template'] && (!isset($params['subject']) || !isset($params['params'])) || !isset($params['template']) && $params['subject'] && !isset($params['message']) && (!isset($this->mail) || !isset($this->mail['message']))) { throw new BadFunctionCallException('Unable to build a new message, missing parameters.'); } $emlKeys = array('to', 'cc', 'bcc'); $emailSet = false; $otherSet = false; foreach ($params as $k => $v) { if (isset($v)) { if (in_array($k, $emlKeys)) { $emailSet = true; } else { $otherSet = true; } } } if ($emailSet && !$otherSet && !isset($this->mail)) { throw new BadFunctionCallException('Unable to build a new message, only emails passed.'); } $mail = null; if (!isset($this->mail)) { //to, [cc], [bcc], [subject, message] //template, to, [cc], [bcc], [subject, params], [prefix], [suffix] $from = isset(config::$emailFrom) ? config::$emailFrom : 'noreply@' . get::domain(); if (is_string($from)) { if ($eml = is::email($from, false)) { $from = (string) $eml; } else { throw new DomainException('From address is not a valid email - see config.1'); } } elseif (is_array($from)) { if ($eml = $this->getEmailAddressArray($from)) { $from = $eml; } else { throw new DomainException('From address is not a valid email - see config'); } } else { throw new DomainException('From address is not a valid email - see config'); } $this->mail = array('from' => $from, 'images' => array()); $mail =& $this->mail; } else { $mail =& $this->mail; } $mail['to'] = $this->emlAddrArray($params['to']); $mail['cc'] = isset($params['cc']) ? $this->emlAddrArray($params['cc']) : null; $mail['bcc'] = isset($params['bcc']) ? $this->emlAddrArray($params['bcc']) : null; if (isset($params['subject'])) { $mail['subject'] = $params['subject']; } if (!isset($params['template']) && $params['message']) { $mail['message'] = $params['message']; $mail['images'] = array(); } elseif ($params['template']) { $file = get::mvc_file('email', $params['template']); if ($file === false) { throw new DomainException('Unable to find email template.'); } $mail['images'] = array(); if (array_key_exists('images', $params['params']) && is_array($params['params']['images'])) { $kill = array(); $imgs = array(); foreach ($params['params']['images'] as $img => $path) { $un = uniqid('PDP-CID-'); $localpath = get::file_path($path); if ($localpath === false) { $kill[] = $img; continue; } $size = getimagesize($localpath); if ($size === false) { $kill[] = $img; continue; } $imgs[$un]['data'] = chunk_split(base64_encode(file_get_contents($localpath))); $imgs[$un]['size'] = $size; $imgs[$un]['name'] = basename($localpath); $imgs[$un]['id'] = $un; $params['params']['images'][$img] = $un; } foreach ($kill as $k) { unset($params['params']['images'][$k]); } $mail['images'] = $imgs; $params['params']['images'] = new emailImageList($params['params']['images']); foreach ($params['params']['images'] as $img => $un) { if ($params['prefix']) { $params['prefix'] = str_replace('cid:' . $img, 'cid:' . $un, $params['prefix']); } if ($params['suffix']) { $params['suffix'] = str_replace('cid:' . $img, 'cid:' . $un, $params['suffix']); } } } $v = new emailView($file, $params['params']); $p = $params['prefix'] ? $params['prefix'] : ''; $s = $params['suffix'] ? $params['suffix'] : ''; $mail['message'] = $p . $v . $s; if (count($mail['images']) > 0 && array_key_exists('images', $params['params']) && is_object($params['params']['images'])) { $lst = $params['params']['images']; $imgs = $lst->toArray(); foreach ($lst->getKeys() as $k) { if (!$lst->wasAccessed($k) && array_key_exists($imgs[$k], $mail['images'])) { unset($mail['images'][$imgs[$k]]); } } } } return $this->mail; }