本文整理汇总了PHP中Idna类的典型用法代码示例。如果您正苦于以下问题:PHP Idna类的具体用法?PHP Idna怎么用?PHP Idna使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Idna类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_encodeEmail
public function test_encodeEmail()
{
$strEmailPrefix = 'user@';
foreach ($this->arrIdnaTests as $strDefaultDomain => $strEncodedDomain) {
$this->assertEquals(Idna::encodeEmail($strEmailPrefix . $strDefaultDomain), $strEmailPrefix . $strEncodedDomain);
}
}
示例2: sendPasswordLink
/**
* Send a lost password e-mail
* @param object
*/
protected function sendPasswordLink($objMember)
{
$objNotification = \NotificationCenter\Model\Notification::findByPk($this->nc_notification);
if ($objNotification === null) {
$this->log('The notification was not found ID ' . $this->nc_notification, __METHOD__, TL_ERROR);
return;
}
$confirmationId = md5(uniqid(mt_rand(), true));
// Store the confirmation ID
$objMember = \MemberModel::findByPk($objMember->id);
$objMember->activation = $confirmationId;
$objMember->save();
$arrTokens = array();
// Add member tokens
foreach ($objMember->row() as $k => $v) {
$arrTokens['member_' . $k] = $v;
}
$arrTokens['recipient_email'] = $objMember->email;
$arrTokens['domain'] = \Idna::decode(\Environment::get('host'));
$arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId;
$objNotification->send($arrTokens);
$this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
// Check whether there is a jumpTo page
if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
$this->jumpToOrReload($objJumpTo->row());
}
$this->reload();
}
示例3: test_isEmail
public function test_isEmail()
{
$arrEmails = array('test@test.ch' => true, 'test@test.c' => false, 'test@test.' => false, 'test@test' => false, 'test@' => false, 'test' => false, Idna::encodeEmail('test@tèst.ch') => true);
foreach ($arrEmails as $strAddress => $blnValidity) {
$this->assertEquals(Validator::isEmail($strAddress), $blnValidity);
}
}
示例4: generate
/**
* Generate the widget and return it as string
* @return string
*/
public function generate()
{
// Hide the Punycode format (see #2750)
if ($this->rgxp == 'email' || $this->rgxp == 'url') {
$this->varValue = \Idna::decode($this->varValue);
}
return sprintf('<input type="%s" name="%s" id="ctrl_%s" class="text%s%s" value="%s"%s%s', $this->hideInput ? 'password' : 'text', $this->strName, $this->strId, $this->hideInput ? ' password' : '', strlen($this->strClass) ? ' ' . $this->strClass : '', specialchars($this->varValue), $this->getAttributes(), $this->strTagEnding) . $this->addSubmit();
}
示例5: __construct
/**
* @param $strType
* @param null $strForceLanguage
*/
public function __construct($strType, $strForceLanguage = null)
{
if (in_array($strType, $GLOBALS['TL_EMAIL'])) {
$this->strType = $strType;
}
$this->strForceLanguage = $strForceLanguage;
// Set default parameters
$this->addParameter('host', \Idna::decode(\Environment::get('host')));
$this->addParameter('admin_name', \BackendUser::getInstance()->name);
}
示例6: addRecipient
private function addRecipient($email, $arrChannels, $strMailText, $intJumpTo)
{
$varInput = \Idna::encodeEmail($email);
// Get the existing active subscriptions
$arrSubscriptions = array();
if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) {
$arrSubscriptions = $objSubscription->fetchEach('pid');
}
$arrNew = array_diff($arrChannels, $arrSubscriptions);
// Return if there are no new subscriptions
if (!is_array($arrNew) || empty($arrNew)) {
return;
}
// Remove old subscriptions that have not been activated yet
if (($objOld = \NewsletterRecipientsModel::findBy(array("email=? AND active=''"), $varInput)) !== null) {
while ($objOld->next()) {
$objOld->delete();
}
}
$time = time();
$strToken = md5(uniqid(mt_rand(), true));
// Add the new subscriptions
foreach ($arrNew as $id) {
$objRecipient = new \NewsletterRecipientsModel();
$objRecipient->pid = $id;
$objRecipient->tstamp = $time;
$objRecipient->email = $varInput;
$objRecipient->active = '';
$objRecipient->addedOn = $time;
$objRecipient->ip = $this->anonymizeIp(\Environment::get('ip'));
$objRecipient->token = $strToken;
$objRecipient->confirmed = '';
$objRecipient->save();
}
// Get the channels
$objChannel = \NewsletterChannelModel::findByIds($arrChannels);
// Prepare the e-mail text
$strText = str_replace('##token##', $strToken, $strMailText);
$strText = str_replace('##domain##', \Environment::get('host'), $strText);
//$strText = str_replace('##link##', \Environment::get('base') . \Environment::get('request') . (($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false) ? '&' : '?') . 'token=' . $strToken, $strText);
$objPageConfirm = \PageModel::findByPk($intJumpTo);
if ($objPageConfirm === null) {
$this->log('Newsletter confirmation page not found, id: ' . $intJumpTo, __CLASS__ . ":" . __METHOD__, TL_NEWSLETTER);
}
$strText = str_replace('##link##', rtrim(\Environment::get('base'), '/') . '/' . $this->generateFrontendUrl($objPageConfirm->row()) . '?token=' . $strToken, $strText);
$strText = str_replace(array('##channel##', '##channels##'), implode("\n", $objChannel->fetchEach('title')), $strText);
// Activation e-mail
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Environment::get('host'));
$objEmail->text = $strText;
$objEmail->sendTo($varInput);
}
示例7: sendPasswordLink
/**
* Send a lost password e-mail
*
* @param \MemberModel $objMember
*/
protected function sendPasswordLink($objMember)
{
$objNotification = \NotificationCenter\Model\Notification::findByPk($this->nc_notification);
if ($objNotification === null) {
$this->log('The notification was not found ID ' . $this->nc_notification, __METHOD__, TL_ERROR);
return;
}
$confirmationId = md5(uniqid(mt_rand(), true));
// Store the confirmation ID
$objMember = \MemberModel::findByPk($objMember->id);
$objMember->activation = $confirmationId;
$objMember->save();
$arrTokens = array();
// Add member tokens
foreach ($objMember->row() as $k => $v) {
if (\Validator::isBinaryUuid($v)) {
$v = \StringUtil::binToUuid($v);
}
$arrTokens['member_' . $k] = specialchars($v);
}
// FIX: Add salutation token
$arrTokens['salutation_user'] = NotificationCenterPlus::createSalutation($GLOBALS['TL_LANGUAGE'], $objMember);
// ENDFIX
$arrTokens['recipient_email'] = $objMember->email;
$arrTokens['domain'] = \Idna::decode(\Environment::get('host'));
$arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId;
// FIX: Add custom change password jump to
if (($objJumpTo = $this->objModel->getRelated('changePasswordJumpTo')) !== null) {
$arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Controller::generateFrontendUrl($objJumpTo->row(), '?token=' . $confirmationId);
}
// ENDFIX
$objNotification->send($arrTokens, $GLOBALS['TL_LANGUAGE']);
$this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
// Check whether there is a jumpTo page
if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
$this->jumpToOrReload($objJumpTo->row());
}
StatusMessage::addSuccess(sprintf($GLOBALS['TL_LANG']['notification_center_plus']['sendPasswordLink']['messageSuccess'], $arrTokens['recipient_email']), $this->objModel->id);
$this->reload();
}
开发者ID:heimrichhannot,项目名称:contao-notification_center_plus,代码行数:45,代码来源:ModulePasswordNotificationCenterPlus.php
示例8: parse
/**
* Parse the template file and return it as string
* @param array
* @return string
*/
public function parse($arrAttributes = null)
{
if ($this->formcontrol_template) {
$this->strTemplate = $this->formcontrol_template;
// Hide the Punycode format (see #2750)
if ($this->rgxp == 'email' || $this->rgxp == 'friendly' || $this->rgxp == 'url') {
$this->varValue = \Idna::decode($this->varValue);
}
if ($this->hideInput) {
$strType = 'password';
} elseif ($this->strFormat != 'xhtml') {
// Use the HTML5 types (see #4138)
// but not the date, time and datetime types (see #5918)
switch ($this->rgxp) {
case 'digit':
$strType = 'number';
break;
case 'phone':
$strType = 'tel';
break;
case 'email':
$strType = 'email';
break;
case 'url':
$strType = 'url';
break;
default:
$strType = 'text';
break;
}
} else {
$strType = 'text';
}
$this->type = $strType;
}
return parent::parse($arrAttributes);
}
示例9: createNewUser
protected function createNewUser($arrData)
{
$arrData['tstamp'] = time();
$arrData['login'] = $this->reg_allowLogin;
$arrData['activation'] = md5(uniqid(mt_rand(), true));
$arrData['dateAdded'] = $arrData['tstamp'];
$pw = $this->getRandomPassword(6);
$arrData['password'] = \Encryption::hash($pw["clear"]);
$arrData['username'] = strtolower($arrData['email']);
$arrData['email'] = strtolower($arrData['email']);
// Set default groups
if (!array_key_exists('groups', $arrData)) {
$arrData['groups'] = $this->reg_groups;
}
// // Disable account
// $arrData['disable'] = 1;
// Send activation e-mail
if ($this->reg_activate) {
$arrChunks = array();
$strConfirmation = $this->reg_text;
preg_match_all('/##[^#]+##/', $strConfirmation, $arrChunks);
foreach ($arrChunks[0] as $strChunk) {
$strKey = substr($strChunk, 2, -2);
switch ($strKey) {
case 'domain':
$strConfirmation = str_replace($strChunk, \Idna::decode(\Environment::get('host')), $strConfirmation);
break;
case 'gen_pw':
$strConfirmation = str_replace($strChunk, $pw["clear"], $strConfirmation);
break;
case 'link':
$strConfirmation = str_replace($strChunk, \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation'], $strConfirmation);
break;
// HOOK: support newsletter subscriptions
// HOOK: support newsletter subscriptions
case 'channel':
case 'channels':
if (!in_array('newsletter', \ModuleLoader::getActive())) {
break;
}
// Make sure newsletter is an array
if (!is_array($arrData['newsletter'])) {
if ($arrData['newsletter'] != '') {
$arrData['newsletter'] = array($arrData['newsletter']);
} else {
$arrData['newsletter'] = array();
}
}
// Replace the wildcard
if (!empty($arrData['newsletter'])) {
$objChannels = \NewsletterChannelModel::findByIds($arrData['newsletter']);
if ($objChannels !== null) {
$strConfirmation = str_replace($strChunk, implode("\n", $objChannels->fetchEach('title')), $strConfirmation);
}
} else {
$strConfirmation = str_replace($strChunk, '', $strConfirmation);
}
break;
default:
$strConfirmation = str_replace($strChunk, $arrData[$strKey], $strConfirmation);
break;
}
}
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['emailSubject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = $strConfirmation;
$objEmail->sendTo($arrData['email']);
}
// Make sure newsletter is an array
if (isset($arrData['newsletter']) && !is_array($arrData['newsletter'])) {
$arrData['newsletter'] = array($arrData['newsletter']);
}
// Create the user
$objNewUser = new \MemberModel();
$objNewUser->setRow($arrData);
$objNewUser->save();
$insertId = $objNewUser->id;
// Assign home directory
if ($this->reg_assignDir) {
$objHomeDir = \FilesModel::findByUuid($this->reg_homeDir);
if ($objHomeDir !== null) {
$this->import('Files');
$strUserDir = standardize($arrData['username']) ?: 'user_' . $insertId;
// Add the user ID if the directory exists
while (is_dir(TL_ROOT . '/' . $objHomeDir->path . '/' . $strUserDir)) {
$strUserDir .= '_' . $insertId;
}
// Create the user folder
new \Folder($objHomeDir->path . '/' . $strUserDir);
$objUserDir = \FilesModel::findByPath($objHomeDir->path . '/' . $strUserDir);
// Save the folder ID
$objNewUser->assignDir = 1;
$objNewUser->homeDir = $objUserDir->uuid;
$objNewUser->save();
}
}
// HOOK: send insert ID and user data
if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) {
//.........这里部分代码省略.........
示例10: generate
/**
* Generate the widget and return it as string
* @return string
*/
public function generate()
{
$type = $this->hideInput ? 'password' : 'text';
if (!$this->multiple) {
// Hide the Punycode format (see #2750)
if ($this->rgxp == 'email' || $this->rgxp == 'url') {
$this->varValue = \Idna::decode($this->varValue);
}
return sprintf('<input type="%s" name="%s" id="ctrl_%s" class="tl_text%s" value="%s"%s onfocus="Backend.getScrollOffset()">%s', $type, $this->strName, $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', specialchars($this->varValue), $this->getAttributes(), $this->wizard);
}
// Return if field size is missing
if (!$this->size) {
return '';
}
if (!is_array($this->varValue)) {
$this->varValue = array($this->varValue);
}
$arrFields = array();
for ($i = 0; $i < $this->size; $i++) {
$arrFields[] = sprintf('<input type="%s" name="%s[]" id="ctrl_%s" class="tl_text_%s" value="%s"%s onfocus="Backend.getScrollOffset()">', $type, $this->strName, $this->strId . '_' . $i, $this->size, specialchars(@$this->varValue[$i]), $this->getAttributes());
}
return sprintf('<div id="ctrl_%s"%s>%s</div>%s', $this->strId, $this->strClass != '' ? ' class="' . $this->strClass . '"' : '', implode(' ', $arrFields), $this->wizard);
}
示例11: doReplace
//.........这里部分代码省略.........
break;
// Conditional tags (if)
// Conditional tags (if)
case 'iflng':
if ($elements[1] != '' && $elements[1] != $objPage->language) {
for (; $_rit < $_cnt; $_rit += 2) {
if ($tags[$_rit + 1] == 'iflng' || $tags[$_rit + 1] == 'iflng::' . $objPage->language) {
break;
}
}
}
unset($arrCache[$strTag]);
break;
// Conditional tags (if not)
// Conditional tags (if not)
case 'ifnlng':
if ($elements[1] != '') {
$langs = \StringUtil::trimsplit(',', $elements[1]);
if (in_array($objPage->language, $langs)) {
for (; $_rit < $_cnt; $_rit += 2) {
if ($tags[$_rit + 1] == 'ifnlng') {
break;
}
}
}
}
unset($arrCache[$strTag]);
break;
// Environment
// Environment
case 'env':
switch ($elements[1]) {
case 'host':
$arrCache[$strTag] = \Idna::decode(\Environment::get('host'));
break;
case 'http_host':
$arrCache[$strTag] = \Idna::decode(\Environment::get('httpHost'));
break;
case 'url':
$arrCache[$strTag] = \Idna::decode(\Environment::get('url'));
break;
case 'path':
$arrCache[$strTag] = \Idna::decode(\Environment::get('base'));
break;
case 'request':
$arrCache[$strTag] = \Environment::get('indexFreeRequest');
break;
case 'ip':
$arrCache[$strTag] = \Environment::get('ip');
break;
case 'referer':
$arrCache[$strTag] = $this->getReferer(true);
break;
case 'files_url':
$arrCache[$strTag] = TL_FILES_URL;
break;
case 'assets_url':
case 'plugins_url':
case 'script_url':
$arrCache[$strTag] = TL_ASSETS_URL;
break;
case 'base_url':
$arrCache[$strTag] = \System::getContainer()->get('request_stack')->getCurrentRequest()->getBaseUrl();
break;
}
break;
示例12: compileRecipients
/**
* Extract the e-mail addresses from the func_get_args() arguments
*
* @param array $arrRecipients The recipients array
*
* @return array An array of e-mail addresses
*/
protected function compileRecipients($arrRecipients)
{
$arrReturn = array();
foreach ($arrRecipients as $varRecipients) {
if (!is_array($varRecipients)) {
$varRecipients = \String::splitCsv($varRecipients);
}
// Support friendly name addresses and internationalized domain names
foreach ($varRecipients as $v) {
list($strName, $strEmail) = \String::splitFriendlyEmail($v);
$strName = trim($strName, ' "');
$strEmail = \Idna::encodeEmail($strEmail);
if ($strName != '') {
$arrReturn[$strEmail] = $strName;
} else {
$arrReturn[] = $strEmail;
}
}
}
return $arrReturn;
}
示例13: isUrl
/**
* Valid URL with special characters allowed (see #6402)
*
* @param mixed $varValue The value to be validated
*
* @return boolean True if the value is a valid URL
*/
public static function isUrl($varValue)
{
return preg_match('/^[\\w\\/.*+?$#%:,;{}()[\\]@&!=~-]+$/u', \Idna::encodeUrl($varValue));
}
示例14: sendUnSubscribeMail
public function sendUnSubscribeMail($channels, $subject = '', $text = '')
{
$objChannel = \Database::getInstance()->prepare("SELECT * FROM tl_newsletter_channel WHERE id IN (" . implode(',', $channels) . ")")->limit(1)->execute();
$objEmail = new \Email();
if (empty($subject)) {
$subject = $objChannel->first()->nl_unsubscribe_subject;
}
if (empty($text)) {
$text = $objChannel->first()->nl_unsubscribe_text;
}
$strSubject = str_replace(array('##channel##', '##channels##'), implode(",", $objChannel->fetchEach('title')), $subject);
$strText = str_replace('##salutation##', $this->getSalutation(), $text);
$strText = str_replace('##domain##', \Idna::decode(\Environment::get('host')), $strText);
$strText = str_replace('##link##', \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $this->token, $strText);
$strText = str_replace(array('##channel##', '##channels##'), implode("\n", $objChannel->fetchEach('title')), $strText);
$objEmail->from = $objChannel->first()->nl_unsubscribe_sender_mail ? $objChannel->first()->nl_unsubscribe_sender_mail : $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $objChannel->first()->nl_unsubscribe_sender_name ? $objChannel->first()->nl_unsubscribe_sender_name : $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = $this->replaceInsertTags($strSubject);
$objEmail->text = $this->replaceInsertTags($strText);
if ($objEmail->sendTo($this->email)) {
$_SESSION['UNSUBSCRIBE_CONFIRM'] = $GLOBALS['TL_LANG']['MSC']['nl_removed'];
return true;
}
return false;
}
示例15: sendPasswordLink
/**
* Create a new user and redirect
* @param object
*/
protected function sendPasswordLink($objMember)
{
$arrChunks = array();
$confirmationId = md5(uniqid(mt_rand(), true));
// Store the confirmation ID
$objMember = \MemberModel::findByPk($objMember->id);
$objMember->activation = $confirmationId;
$objMember->save();
$strConfirmation = $this->reg_password;
preg_match_all('/##[^#]+##/', $strConfirmation, $arrChunks);
foreach ($arrChunks[0] as $strChunk) {
$strKey = substr($strChunk, 2, -2);
switch ($strKey) {
case 'domain':
$strConfirmation = str_replace($strChunk, \Idna::decode(\Environment::get('host')), $strConfirmation);
break;
case 'link':
$strConfirmation = str_replace($strChunk, \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId, $strConfirmation);
break;
default:
try {
$strConfirmation = str_replace($strChunk, $objMember->{$strKey}, $strConfirmation);
} catch (\Exception $e) {
$strConfirmation = str_replace($strChunk, '', $strConfirmation);
$this->log('Invalid wildcard "' . $strKey . '" used in password request e-mail', __METHOD__, TL_GENERAL, $e->getMessage());
}
break;
}
}
// Send e-mail
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['passwordSubject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = $strConfirmation;
$objEmail->sendTo($objMember->email);
$this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
// Check whether there is a jumpTo page
if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
$this->jumpToOrReload($objJumpTo->row());
}
$this->reload();
}