本文整理汇总了PHP中FabrikWorker::isEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikWorker::isEmail方法的具体用法?PHP FabrikWorker::isEmail怎么用?PHP FabrikWorker::isEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FabrikWorker
的用法示例。
在下文中一共展示了FabrikWorker::isEmail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validate the elements data against the rule
*
* @param string $data To check
* @param int $repeatCounter Repeat group counter
*
* @return bool true if validation passes, false if fails
*/
public function validate($data, $repeatCounter)
{
$email = $data;
// Could be a drop-down with multi-values
if (is_array($email)) {
$email = implode('', $email);
}
// Decode as it can be posted via ajax
// (but first % encode any + characters, as urldecode() will turn + into space)
$email = urldecode(str_replace('+', '%2B', $email));
$params = $this->getParams();
$allow_empty = $params->get('isemail-allow_empty');
if ($allow_empty == '1' and empty($email)) {
return true;
}
// $$$ hugh - let's try using new helper func instead of rolling our own.
if (FabrikWorker::isEmail($email)) {
if ($params->get('isemail-check_mx', '0') === '1') {
list($user, $domain) = explode('@', $data);
if (!checkdnsrr($domain, 'MX')) {
return false;
}
}
return true;
} else {
return false;
}
}
示例2: validate
/**
* Validate the elements data against the rule
*
* @param string $data to check
* @param object &$elementModel element Model
* @param int $pluginc plugin sequence ref
* @param int $repeatCounter repeat group counter
*
* @return bool true if validation passes, false if fails
*/
public function validate($data, &$elementModel, $pluginc, $repeatCounter)
{
$email = $data;
// Could be a dropdown with multivalues
if (is_array($email)) {
$email = implode('', $email);
}
// Decode as it can be posted via ajax
$email = urldecode($email);
$params = $this->getParams();
$allow_empty = $params->get('isemail-allow_empty');
$allow_empty = $allow_empty[$pluginc];
if ($allow_empty == '1' and empty($email)) {
return true;
}
// $$$ hugh - let's try using new helper func instead of rolling our own.
return FabrikWorker::isEmail($email);
// $$$ keeping this code just in case, but shouldn't be reached.
// First, we check that there's one symbol, and that the lengths are right
if (!preg_match("/[^@]{1,64}@[^@]{1,255}/", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < count($local_array); $i++) {
if (!preg_match("/^(([A-Za-z0-9!#\$%&'*+\\/=?^_`{|}~-][A-Za-z0-9!#\$%&'*+\\/=?^_`{|}~\\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))\$/", $local_array[0])) {
return false;
}
}
// Check if domain is IP. If not, it should be valid domain name
if (!preg_match("/^\\[?[0-9\\.]+\\]?\$/", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (count($domain_array) < 2) {
// Not enough parts to domain
return false;
}
for ($i = 0; $i < count($domain_array); $i++) {
if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))\$/", $domain_array[$i])) {
return false;
}
}
}
return true;
}
示例3: validate
/**
* Validate the elements data against the rule
*
* @param string $data To check
* @param int $repeatCounter Repeat group counter
*
* @return bool true if validation passes, false if fails
*/
public function validate($data, $repeatCounter)
{
$email = $data;
// Could be a dropdown with multivalues
if (is_array($email)) {
$email = implode('', $email);
}
// Decode as it can be posted via ajax
$email = urldecode($email);
$params = $this->getParams();
$allow_empty = $params->get('isemail-allow_empty');
if ($allow_empty == '1' and empty($email)) {
return true;
}
// $$$ hugh - let's try using new helper func instead of rolling our own.
return FabrikWorker::isEmail($email);
}
示例4: _guessLinkType
/**
* Format guess link type
*
* @param string &$value Original field value
* @param array $data Record data
*
* @return void
*/
protected function _guessLinkType(&$value, $data)
{
$params = $this->getParams();
if ($params->get('guess_linktype') == '1') {
$w = new FabrikWorker();
$opts = $this->linkOpts();
$title = $params->get('link_title', '');
if (FabrikWorker::isEmail($value) || JString::stristr($value, 'http')) {
} elseif (JString::stristr($value, 'www.')) {
$value = 'http://' . $value;
}
if ($title !== '') {
$opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data));
}
$label = FArrayHelper::getValue($opts, 'title', '') !== '' ? $opts['title'] : $value;
$value = FabrikHelperHTML::a($value, $label, $opts);
}
}
示例5: process
/**
* Do the plugin action
*
* @param array &$data data
*
* @return int number of records updated
*/
public function process(&$data)
{
jimport('joomla.mail.helper');
$params = $this->getParams();
$msg = $params->get('message');
FabrikHelperHTML::runContentPlugins($msg);
$to = explode(',', $params->get('to'));
$w = new FabrikWorker();
$params->get('cronemail_return', '') != '' ? $MailFrom = $params->get('cronemail_return') : ($MailFrom = $this->app->get('mailfrom'));
$params->get('cronemail_from', '') != '' ? $FromName = $params->get('cronemail_from') : ($FromName = $this->app->get('fromname'));
$subject = $params->get('subject', 'Fabrik cron job');
$eval = $params->get('cronemail-eval');
$condition = $params->get('cronemail_condition', '');
$updates = array();
$this->log = '';
foreach ($data as $group) {
if (is_array($group)) {
foreach ($group as $row) {
if (!empty($condition)) {
$this_condition = $w->parseMessageForPlaceHolder($condition, $row);
if (eval($this_condition) === false) {
continue;
}
}
$row = JArrayHelper::fromObject($row);
foreach ($to as $thisTo) {
$thisTo = $w->parseMessageForPlaceHolder($thisTo, $row);
if (FabrikWorker::isEmail($thisTo)) {
$thisMsg = $w->parseMessageForPlaceHolder($msg, $row);
if ($eval) {
$thisMsg = eval($thisMsg);
}
$thisSubject = $w->parseMessageForPlaceHolder($subject, $row);
$mail = JFactory::getMailer();
$res = $mail->sendMail($MailFrom, $FromName, $thisTo, $thisSubject, $thisMsg, true);
if (!$res) {
$this->log .= "\n failed sending to {$thisTo}";
} else {
$this->log .= "\n sent to {$thisTo}";
}
} else {
$this->log .= "\n {$thisTo} is not an email address";
}
}
$updates[] = $row['__pk_val'];
}
}
}
$field = $params->get('cronemail-updatefield');
if (!empty($updates) && trim($field) != '') {
// Do any update found
/** @var FabrikFEModelList $listModel */
$listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
$listModel->setId($params->get('table'));
$table = $listModel->getTable();
$field = $params->get('cronemail-updatefield');
$value = $params->get('cronemail-updatefield-value');
if ($params->get('cronemail-updatefield-eval', '0') == '1') {
$value = @eval($value);
}
$field = str_replace('___', '.', $field);
$fabrikDb = $listModel->getDb();
$query = $fabrikDb->getQuery(true);
$query->update($table->db_table_name)->set($field . ' = ' . $fabrikDb->quote($value))->where($table->db_primary_key . ' IN (' . implode(',', $updates) . ')');
$this->log .= "\n update query: {$query}";
$fabrikDb->setQuery($query);
$fabrikDb->execute();
}
$this->log .= "\n updates " . count($updates) . " records";
return count($updates);
}
示例6: mailMerged
/**
* Sent mail merge
*
* @param $firstRow
* @param $mergedMsg
* @param $sent
* @param $notSent
*
* @return array
* @throws Exception
*/
private function mailMerged($firstRow, $mergedMsg, $sent, $notSent)
{
$params = $this->getParams();
$input = $this->app->input;
list($replyEmail, $replyEmailName) = $this->_replyEmailName($firstRow);
list($emailFrom, $fromName) = $this->_fromEmailName($firstRow);
$w = new FabrikWorker();
$toType = $this->_toType();
$to = $this->_to();
$oldStyle = $this->_oldStyle();
$toHow = $this->_toHow();
$mailTo = $toType == 'list' ? $firstRow->{$to} : $to;
$subject = $input->get('subject', '', 'string');
$thisTos = explode(',', $w->parseMessageForPlaceHolder($mailTo, $firstRow));
$thisSubject = $w->parseMessageForPlaceHolder($subject, $firstRow);
$preamble = $params->get('emailtable_message_preamble', '');
$postamble = $params->get('emailtable_message_postamble', '');
$mergedMsg = $preamble . $mergedMsg . $postamble;
$coverMessage = nl2br($input->get('message', '', 'html'));
$cc = null;
$bcc = null;
if (!$oldStyle) {
$mergedMsg = $coverMessage . $mergedMsg;
}
if ($toHow == 'single') {
foreach ($thisTos as $toKey => $thisTo) {
$thisTo = $w->parseMessageForPlaceholder($thisTo, $firstRow);
if (!FabrikWorker::isEmail($thisTo)) {
unset($thisTos[$toKey]);
$notSent++;
} else {
$mailTos[$toKey] = $thisTo;
}
}
if ($notSent > 0) {
$thisTos = array_values($thisTos);
}
$sent = count($thisTos);
if ($sent > 0) {
$res = FabrikWorker::sendMail($emailFrom, $fromName, $thisTos, $thisSubject, $mergedMsg, true, $cc, $bcc, $this->filepath, $replyEmail, $replyEmailName);
}
} else {
foreach ($thisTos as $thisTo) {
if (FabrikWorker::isEmail($thisTo)) {
$res = FabrikWorker::sendMail($emailFrom, $fromName, $thisTo, $thisSubject, $mergedMsg, true, $cc, $bcc, $this->filepath, $replyEmail, $replyEmailName);
if ($res) {
$sent++;
} else {
$notSent++;
}
} else {
$notSent++;
}
}
}
return array($sent, $notSent);
}
示例7: onStoreRow
/**
* Trigger called when a row is stored.
* If we are creating a new record, and the element was set to readonly
* then insert the users data into the record to be stored
*
* @param array &$data Data to store
* @param int $repeatCounter Repeat group index
*
* @return bool If false, data should not be added.
*/
public function onStoreRow(&$data, $repeatCounter = 0)
{
if (!parent::onStoreRow($data, $repeatCounter)) {
return false;
}
// $$$ hugh - if importing a CSV, just use the data as is
if ($this->getListModel()->importingCSV) {
return true;
}
$input = $this->app->input;
// $$$ hugh - special case, if we have just run the fabrikjuser plugin, we need to
// use the 'newuserid' as set by the plugin.
$newUserId = $input->getInt('newuserid', 0);
if (!empty($newUserId)) {
$newUserIdElement = $input->get('newuserid_element', '');
$thisFullName = $this->getFullName(true, false);
if ($newUserIdElement == $thisFullName) {
return true;
}
}
$element = $this->getElement();
$params = $this->getParams();
/*
* After a failed validation, if readonly for ACL's, it may be JSON, and urlencoded, like ["94"]
*/
$data[$element->name] = is_array($data[$element->name]) ? $data[$element->name][0] : $data[$element->name];
$data[$element->name] = html_entity_decode($data[$element->name]);
if (FabrikWorker::isJSON($data[$element->name])) {
$data[$element->name] = FabrikWorker::JSONtoData($data[$element->name], true);
}
$data[$element->name] = is_array($data[$element->name]) ? $data[$element->name][0] : $data[$element->name];
/**
* $$$ hugh - special case for social plugins (like CB plugin). If plugin sets
* fabrik.plugin.profile_id, and 'user_use_social_plugin_profile' param is set,
* and we are creating a new row, then use the session data as the user ID.
* This allows user B to view a table in a CB profile for user A, do an "Add",
* and have the user element set to user A's ID.
*/
// TODO - make this table/form specific, but not so easy to do in CB plugin
if ((int) $params->get('user_use_social_plugin_profile', 0)) {
//if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport')
if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) {
$session = JFactory::getSession();
if ($session->has('fabrik.plugin.profile_id')) {
$data[$element->name] = $session->get('fabrik.plugin.profile_id');
$data[$element->name . '_raw'] = $data[$element->name];
// $session->clear('fabrik.plugin.profile_id');
return true;
}
}
}
// $$$ rob also check we aren't importing from CSV - if we are ignore
//if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport')
if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) {
// $$$ rob if we cant use the element or its hidden force the use of current logged in user
if (!$this->canUse() || $this->getElement()->hidden == 1) {
$data[$element->name] = $this->user->get('id');
$data[$element->name . '_raw'] = $data[$element->name];
}
} else {
if ($this->updateOnEdit()) {
$data[$element->name] = $this->user->get('id');
$data[$element->name . '_raw'] = $data[$element->name];
// Set the formDataWithTableName so any plugins (like email) pick it up with getProcessData()
$thisFullName = $this->getFullName(true, false);
$formModel = $this->getFormModel();
$groupModel = $this->getGroupModel();
if ($groupModel->canRepeat()) {
$formModel->formDataWithTableName[$thisFullName][$repeatCounter] = array($data[$element->name]);
$formModel->formDataWithTableName[$thisFullName . '_raw'][$repeatCounter] = array($data[$element->name]);
} else {
$formModel->formDataWithTableName[$thisFullName] = array($data[$element->name]);
$formModel->formDataWithTableName[$thisFullName . '_raw'] = array($data[$element->name]);
}
// $$$ hugh - need to add to updatedByPlugin() in order to override write access settings.
// This allows us to still 'update on edit' when element is write access controlled.
if (!$this->canUse()) {
$this->getFormModel()->updatedByPlugin($thisFullName, $this->user->get('id'));
}
} else {
if ($this->getListModel()->importingCSV) {
$formData = $this->getFormModel()->formData;
$userId = FArrayHelper::getValue($formData, $element->name, '');
if (!empty($userId) && !is_numeric($userId)) {
$user = JFactory::getUser($userId);
$newUserId = $user->get('id');
if (empty($newUserId) && FabrikWorker::isEmail($userId)) {
$db = $this->_db;
$query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('email') . ' = ' . $db-- > q($userId));
$db->setQuery($query, 0, 1);
//.........这里部分代码省略.........
示例8: log
//.........这里部分代码省略.........
$csvMsg[] = "UserAgent";
}
if ($params->get('compare_data') == 1) {
$csvMsg[] = "\"" . FText::_('COMPARE_DATA_LABEL_CSV') . "\"";
}
}
// Inserting data in CSV with actual line break as row separator
$csvMsg[] = "\n\"" . $date . "\"";
if ($params->get('logs_record_ip') == 1) {
$csvMsg[] = "\"" . FabrikString::filteredIp() . "\"";
}
if ($params->get('logs_record_referer') == 1) {
$csvMsg[] = "\"" . $http_referrer . "\"";
}
if ($params->get('logs_record_useragent') == 1) {
$csvMsg[] = "\"" . $input->server->getString('HTTP_USER_AGENT') . "\"";
}
if ($params->get('compare_data') == 1) {
$csvMsg[] = "\"" . $result_compare . "\"";
}
$csvMsg = implode(",", $csvMsg);
if ($send_email) {
$email_msg = $csvMsg;
}
if ($make_file) {
if ($buffer !== '') {
$csvMsg = $buffer . $csvMsg;
}
JFile::write($logsFile, $csvMsg);
}
}
}
}
if ($params->get('logs_record_in_db') == 1) {
// In which table?
if ($params->get('record_in') == '') {
$rdb = '#__fabrik_log';
} else {
$db_suff = $params->get('record_in');
$form = $formModel->getForm();
$fid = $form->id;
$db->setQuery("SELECT " . $db->qn('db_table_name') . " FROM " . $db->qn('#__fabrik_lists') . " WHERE " . $db->qn('form_id') . " = " . (int) $fid);
$tname = $db->loadResult();
$rdb = $db->qn($tname . $db_suff);
}
// Making the message to record
if ($params->get('custom_msg') != '') {
$message = preg_replace('/<br\\/>/', ' ', $custom_msg);
} else {
$message = $this->makeStandardMessage($result_compare);
}
/* $$$ hugh - FIXME - not sure about the option driven $create_custom_table stuff, as this won't work
* if they add an option to an existing log table. We should probably just create all the optional columns
* regardless.
*/
if ($params->get('record_in') == '') {
$in_db = "INSERT INTO {$rdb} (" . $db->qn('referring_url') . ", " . $db->qn('message_type') . ", " . $db->qn('message') . ") VALUES (" . $db->q($http_referrer) . ", " . $db->q($messageType) . ", " . $db->q($message) . ");";
$db->setQuery($in_db);
$db->execute();
} else {
$create_custom_table = "CREATE TABLE IF NOT EXISTS {$rdb} (" . $db->qn('id') . " int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, {$clabels_createdb});";
$db->setQuery($create_custom_table);
$db->execute();
$in_db = "INSERT INTO {$rdb} ({$clabels_db}) VALUES ({$cdata_db});";
$db->setQuery($in_db);
if (!$db->execute()) {
/* $$$ changed to always use db fields even if not selected
* so logs already created may need optional fields added.
* try adding every field we should have, don't care if query fails.
*/
foreach ($clabelsCreateDb as $insert) {
$db->setQuery("ALTER TABLE ADD {$insert} AFTER `id`");
$db->execute();
}
// ... and try the insert query again
$db->setQuery($in_db);
$db->execute();
}
}
}
if ($send_email) {
jimport('joomla.mail.helper');
$emailFrom = $this->config->get('mailfrom');
$emailTo = explode(',', $w->parseMessageForPlaceholder($params->get('log_send_email_to', '')));
$subject = strip_tags($w->parseMessageForPlaceholder($params->get('log_send_email_subject', 'log event')));
foreach ($emailTo as $email) {
$email = trim($email);
if (empty($email)) {
continue;
}
if (FabrikWorker::isEmail($email)) {
$mail = JFactory::getMailer();
$res = $mail->sendMail($emailFrom, $emailFrom, $email, $subject, $email_msg, true);
} else {
$app->enqueueMessage(JText::sprintf('DID_NOT_SEND_EMAIL_INVALID_ADDRESS', $email));
}
}
}
return true;
}
示例9: createUser
public function createUser(&$listModel)
{
// Include the JLog class.
jimport('joomla.log.log');
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$logMessageType = 'plg.list.listcsv.csv_import_user.information';
$formModel = $listModel->getFormModel();
$data = $formModel->formData;
$clear_passwd = '';
// Load in the com_user language file
$lang = JFactory::getLanguage();
$lang->load('com_user');
// Grab username, name and email
// @TODO - sanity check these config vars (plus userid) to make sure they have been edited.
$userdata['username'] = $data[$this->username_element];
$userdata['email'] = $data[$this->email_element];
$userdata['name'] = $data[$this->name_element];
if (!FabrikWorker::isEmail($userdata['email'])) {
if ($app->isAdmin()) {
$app->enqueueMessage("No email for {$userdata['username']}");
}
JLog::add('No email for ' . $userdata['username'], JLog::NOTICE, $logMessageType);
return false;
}
$query->select('*')->from('#__users')->where('username = ' . $db->quote($userdata['username']));
$db->setQuery($query);
$existing_user = $db->loadObject();
if (!empty($existing_user)) {
$user_id = $existing_user->id;
$isNew = false;
} else {
$query->clear();
$query->select('*')->from('#__users')->where('username != ' . $db->quote($userdata['username']) . ' AND email = ' . $db->quote($userdata['email']));
$db->setQuery($query);
$existing_email = $db->loadObject();
if (!empty($existing_email)) {
$msg = 'Email ' . $userdata['email'] . ' for ' . $userdata['username'] . ' already in use by ' . $existing_email->username;
if ($app->isAdmin()) {
$app->enqueueMessage($msg);
}
JLog::add($msg, JLog::NOTICE, $logMessageType);
return false;
}
$user_id = 0;
$isNew = true;
if (!empty($this->password_element)) {
$clear_passwd = $userdata['password'] = $userdata['password2'] = $data[$this->password_element];
$data[$this->password_element] = '';
} else {
$clear_passwd = $userdata['password'] = $userdata['password2'] = $this->rand_str();
}
}
$user = new JUser($user_id);
// $userdata['gid'] = 18;
$userdata['block'] = 0;
$userdata['id'] = $user_id;
if ($isNew) {
$now = JFactory::getDate();
$user->set('registerDate', $now->toSql());
}
if (!$user->bind($userdata)) {
if ($app->isAdmin()) {
$app->enqueueMessage(FText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
$app->enqueueMessage($user->getError(), 'error');
}
JLog::add('Error binding user info for: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
return false;
}
if (!$user->save()) {
if ($app->isAdmin()) {
$app->enqueueMessage(FText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
$app->enqueueMessage($user->getError(), 'error');
}
JLog::add('Error storing user info for: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
return false;
}
// Save clear text password if requested
if ($isNew && !empty($this->first_password_element)) {
$data[$this->first_password_element] = $clear_passwd;
}
// Store the userid
$data[$this->userid_element] = $user->get('id');
// Optionally set 'created' flag
if (!empty($this->user_created_element)) {
$data[$this->user_created_element] = $this->user_created_value;
}
if ($isNew) {
JLog::add('Created user: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
} else {
JLog::add('Modified user: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
}
return true;
}
示例10: check
/**
* Check if the submitted details are ok
*
* @param array $post Posted data
*
* @return bool
*/
protected function check($post)
{
$params = $this->getParams();
$formModel = $this->getModel();
$userElement = $formModel->getElement($params->get('juser_field_userid'), true);
$userElName = $userElement === false ? false : $userElement->getFullName();
$userId = (int) $post['id'];
$db = FabrikWorker::getDbo(true);
$ok = true;
jimport('joomla.mail.helper');
if ($post['name'] == '') {
$formModel->errors[$this->namefield][0][] = FText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_YOUR_NAME');
$this->raiseError($formModel->errors, $this->namefield, FText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_YOUR_NAME'));
$ok = false;
}
if ($post['username'] == '') {
$this->raiseError($formModel->errors, $this->usernamefield, FText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_A_USER_NAME'));
$ok = false;
}
if (preg_match("#[<>\"'%;()&]#i", $post['username']) || JString::strlen(utf8_decode($post['username'])) < 2) {
$this->raiseError($formModel->errors, $this->usernamefield, JText::sprintf('VALID_AZ09', FText::_('Username'), 2));
$ok = false;
}
if (trim($post['email']) == "" || !FabrikWorker::isEmail($post['email'])) {
$this->raiseError($formModel->errors, $this->emailfield, FText::_('JLIB_DATABASE_ERROR_VALID_MAIL'));
$ok = false;
}
if (empty($post['password'])) {
if ($userId === 0) {
$this->raiseError($formModel->errors, $this->passwordfield, FText::_('Please enter a password'));
$ok = false;
}
} else {
if ($post['password'] != $post['password2']) {
$this->raiseError($formModel->errors, $this->passwordfield, FText::_('PASSWORD DO NOT MATCH.'));
$ok = false;
}
}
// Check for existing username
$query = $db->getQuery(true);
$query->select('COUNT(*)')->from('#__users')->where('username = ' . $db->q($post['username']))->where('id != ' . (int) $userId);
$db->setQuery($query);
$xid = (int) $db->loadResult();
if ($xid > 0) {
$this->raiseError($formModel->errors, $this->usernamefield, FText::_('JLIB_DATABASE_ERROR_USERNAME_INUSE'));
$ok = false;
}
// Check for existing email
$query->clear();
$query->select('COUNT(*)')->from('#__users')->where('email = ' . $db->q($post['email']))->where('id != ' . (int) $userId);
$db->setQuery($query);
$xid = (int) $db->loadResult();
if ($xid > 0) {
$this->raiseError($formModel->errors, $this->emailfield, FText::_('JLIB_DATABASE_ERROR_EMAIL_INUSE'));
$ok = false;
}
return $ok;
}
示例11: sendMail
/**
* Send email
*
* @param string $email Email
*
* @throws RuntimeException
*
* @return bool
*/
public function sendMail($email)
{
JSession::checkToken() or die('Invalid Token');
$input = $this->app->input;
/*
* First, make sure the form was posted from a browser.
* For basic web-forms, we don't care about anything
* other than requests from a browser:
*/
if (is_null($input->server->get('HTTP_USER_AGENT'))) {
throw new RuntimeException(FText::_('JERROR_ALERTNOAUTHOR'), 500);
}
// Make sure the form was indeed POST'ed:
// (requires your html form to use: action="post")
if (!$input->server->get('REQUEST_METHOD') == 'POST') {
throw new RuntimeException(FText::_('JERROR_ALERTNOAUTHOR'), 500);
}
// Attempt to defend against header injections:
$badStrings = array('Content-Type:', 'MIME-Version:', 'Content-Transfer-Encoding:', 'bcc:', 'cc:');
// Loop through each POST'ed value and test if it contains
// one of the $badStrings:
foreach ($_POST as $k => $v) {
foreach ($badStrings as $v2) {
if (JString::strpos($v, $v2) !== false) {
throw new RuntimeException(FText::_('JERROR_ALERTNOAUTHOR'), 500);
}
}
}
// Made it past spammer test, free up some memory
// and continue rest of script:
unset($k, $v, $v2, $badStrings);
$email = $input->getString('email', '');
$yourName = $input->getString('yourname', '');
$yourEmail = $input->getString('youremail', '');
$subject_default = JText::sprintf('Email from', $yourName);
$subject = $input->getString('subject', $subject_default);
jimport('joomla.mail.helper');
if (!$email || !$yourEmail || FabrikWorker::isEmail($email) == false || FabrikWorker::isEmail($yourEmail) == false) {
$this->app->enqueueMessage(FText::_('PHPMAILER_INVALID_ADDRESS'));
}
$siteName = $this->config->get('sitename');
// Link sent in email
$link = $input->get('referrer', '', 'string');
// Message text
$msg = JText::sprintf('COM_FABRIK_EMAIL_MSG', $siteName, $yourName, $yourEmail, $link);
// Mail function
$mail = JFactory::getMailer();
return $mail->sendMail($yourEmail, $yourName, $email, $subject, $msg);
}
示例12: _guessLinkType
/**
* Format guess link type
*
* @param string &$value Original field value
* @param array $data Record data
* @param int $repeatCounter Repeat counter
*
* @return void
*/
protected function _guessLinkType(&$value, $data, $repeatCounter = 0)
{
$params = $this->getParams();
$guessed = false;
if ($params->get('guess_linktype') == '1') {
$w = new FabrikWorker();
$opts = $this->linkOpts();
$title = $params->get('link_title', '');
if (FabrikWorker::isEmail($value) || JString::stristr($value, 'http')) {
$guessed = true;
} elseif (JString::stristr($value, 'www.')) {
$value = 'http://' . $value;
$guessed = true;
}
if ($title !== '') {
$opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data));
}
$value = FabrikHelperHTML::a($value, $value, $opts);
}
}
示例13: onAfterProcess
/**
* Run right at the end of the form processing
* form needs to be set to record in database for this to hook to be called
*
* @return bool
*/
public function onAfterProcess()
{
$profiler = JProfiler::getInstance('Application');
JDEBUG ? $profiler->mark("email: start: onAfterProcess") : null;
$params = $this->getParams();
$input = $this->app->input;
jimport('joomla.mail.helper');
$w = new FabrikWorker();
/** @var \FabrikFEModelForm $formModel */
$formModel = $this->getModel();
$emailTemplate = JPath::clean(JPATH_SITE . '/plugins/fabrik_form/email/tmpl/' . $params->get('email_template', ''));
$this->data = $this->getProcessData();
/* $$$ hugh - moved this to here from above the previous line, 'cos it needs $this->data
* check if condition exists and is met
*/
if ($this->alreadySent() || !$this->shouldProcess('email_conditon', null, $params)) {
return true;
}
/**
* Added option to run content plugins on message text. Note that rather than run it one time at the
* end of the following code, after we have assembled all the various options in to a single $message,
* it needs to be run separately on each type of content. This is because we do placeholder replacement
* in various places, which will strip all {text} which doesn't match element names.
*/
$runContentPlugins = $params->get('email_run_content_plugins', '0') === '1';
$contentTemplate = $params->get('email_template_content');
$content = $contentTemplate != '' ? FabrikHelperHTML::getContentTemplate($contentTemplate, 'both', $runContentPlugins) : '';
// Always send as html as even text email can contain html from wysiwyg editors
$htmlEmail = true;
$messageTemplate = '';
if (JFile::exists($emailTemplate)) {
$messageTemplate = JFile::getExt($emailTemplate) == 'php' ? $this->_getPHPTemplateEmail($emailTemplate) : $this->_getTemplateEmail($emailTemplate);
// $$$ hugh - added ability for PHP template to return false to abort, same as if 'condition' was was false
if ($messageTemplate === false) {
return true;
}
if ($runContentPlugins === true) {
FabrikHelperHTML::runContentPlugins($messageTemplate);
}
$messageTemplate = str_replace('{content}', $content, $messageTemplate);
}
$messageText = $params->get('email_message_text', '');
if (!empty($messageText)) {
if ($runContentPlugins === true) {
FabrikHelperHTML::runContentPlugins($messageText);
}
$messageText = str_replace('{content}', $content, $messageText);
$messageText = str_replace('{template}', $messageTemplate, $messageText);
$messageText = $w->parseMessageForPlaceholder($messageText, $this->data, false);
}
if (!empty($messageText)) {
$message = $messageText;
} elseif (!empty($messageTemplate)) {
$message = $messageTemplate;
} elseif (!empty($content)) {
$message = $content;
} else {
$message = $this->_getTextEmail();
}
$this->addAttachments();
$cc = null;
$bcc = null;
// $$$ hugh - test stripslashes(), should be safe enough.
$message = stripslashes($message);
$editURL = COM_FABRIK_LIVESITE . 'index.php?option=com_' . $this->package . '&view=form&fabrik=' . $formModel->get('id') . '&rowid=' . $input->get('rowid', '', 'string');
$viewURL = COM_FABRIK_LIVESITE . 'index.php?option=com_' . $this->package . '&view=details&fabrik=' . $formModel->get('id') . '&rowid=' . $input->get('rowid', '', 'string');
$editLink = '<a href="' . $editURL . '">' . FText::_('EDIT') . '</a>';
$viewLink = '<a href="' . $viewURL . '">' . FText::_('VIEW') . '</a>';
$message = str_replace('{fabrik_editlink}', $editLink, $message);
$message = str_replace('{fabrik_viewlink}', $viewLink, $message);
$message = str_replace('{fabrik_editurl}', $editURL, $message);
$message = str_replace('{fabrik_viewurl}', $viewURL, $message);
// $$$ rob if email_to is not a valid email address check the raw value to see if that is
$emailTo = explode(',', $params->get('email_to'));
foreach ($emailTo as &$emailKey) {
$emailKey = $w->parseMessageForPlaceholder($emailKey, $this->data, false);
// Can be in repeat group in which case returns "email1,email2"
$emailKey = explode(',', $emailKey);
foreach ($emailKey as &$key) {
// $$$ rob added strstr test as no point trying to add raw suffix if not placeholder in $emailKey
if (!FabrikWorker::isEmail($key) && trim($key) !== '' && strstr($key, '}')) {
$key = explode('}', $key);
if (substr($key[0], -4) !== '_raw') {
$key = $key[0] . '_raw}';
} else {
$key = $key[0] . '}';
}
$key = $w->parseMessageForPlaceholder($key, $this->data, false);
}
}
}
// Reduce back down to single dimension array
foreach ($emailTo as $i => $a) {
foreach ($a as $v) {
//.........这里部分代码省略.........
示例14: onStoreRow
/**
* Trigger called when a row is stored.
* If we are creating a new record, and the element was set to readonly
* then insert the users data into the record to be stored
*
* @param array &$data Data to store
* @param int $repeatCounter Repeat group index
*
* @return bool If false, data should not be added.
*/
public function onStoreRow(&$data, $repeatCounter = 0)
{
if (!parent::onStoreRow($data, $repeatCounter)) {
return false;
}
$app = JFactory::getApplication();
$input = $app->input;
// $$$ hugh - special case, if we have just run the fabrikjuser plugin, we need to
// use the 'newuserid' as set by the plugin.
$newuserid = $input->getInt('newuserid', 0);
if (!empty($newuserid)) {
$newuserid_element = $input->get('newuserid_element', '');
$this_fullname = $this->getFullName(true, false);
if ($newuserid_element == $this_fullname) {
return true;
}
}
$element = $this->getElement();
$params = $this->getParams();
/**
* $$$ hugh - special case for social plugins (like CB plugin). If plugin sets
* fabrik.plugin.profile_id, and 'user_use_social_plugin_profile' param is set,
* and we are creating a new row, then use the session data as the user ID.
* This allows user B to view a table in a CB profile for user A, do an "Add",
* and have the user element set to user A's ID.
*/
// TODO - make this table/form specific, but not so easy to do in CB plugin
if ((int) $params->get('user_use_social_plugin_profile', 0)) {
//if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport')
if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) {
$session = JFactory::getSession();
if ($session->has('fabrik.plugin.profile_id')) {
$data[$element->name] = $session->get('fabrik.plugin.profile_id');
$data[$element->name . '_raw'] = $data[$element->name];
// $session->clear('fabrik.plugin.profile_id');
return true;
}
}
}
// $$$ rob also check we aren't importing from CSV - if we are ignore
//if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport')
if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) {
// $$$ rob if we cant use the element or its hidden force the use of current logged in user
if (!$this->canUse() || $this->getElement()->hidden == 1) {
$user = JFactory::getUser();
$data[$element->name] = $user->get('id');
$data[$element->name . '_raw'] = $data[$element->name];
}
} else {
if ($this->updateOnEdit()) {
$user = JFactory::getUser();
$data[$element->name] = $user->get('id');
$data[$element->name . '_raw'] = $data[$element->name];
// $$$ hugh - need to add to updatedByPlugin() in order to override write access settings.
// This allows us to still 'update on edit' when element is write access controlled.
if (!$this->canUse()) {
$this_fullname = $this->getFullName(true, false);
$this->getFormModel()->updatedByPlugin($this_fullname, $user->get('id'));
}
} else {
if ($this->getListModel()->importingCSV) {
$formData = $this->getFormModel()->formData;
$userid = JArrayHelper::getValue($formData, $element->name, '');
if (!empty($userid) && !is_numeric($userid)) {
$user = JFactory::getUser($userid);
$new_userid = $user->get('id');
if (empty($new_userid) && FabrikWorker::isEmail($userid)) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('email') . ' = ' . $db->quote($userid));
$db->setQuery($query, 0, 1);
$new_userid = (int) $db->loadResult();
}
$data[$element->name] = $new_userid;
}
}
}
}
return true;
}
示例15: sendEmails
/**
* Send notification emails
*
* @param string $ids csv list of row ids.
*
* @return void
*/
protected function sendEmails($ids)
{
$params = $this->getParams();
$model = $this->getModel();
// Ensure that yesno exports text and not bootstrap icon.
$model->setOutputFormat('csv');
$emailColID = $params->get('update_email_element', '');
$emailTo = $params->get('update_email_to', '');
if (!empty($emailColID) || !empty($emailTo)) {
$w = new FabrikWorker();
jimport('joomla.mail.helper');
$aids = explode(',', $ids);
$message = $params->get('update_email_msg');
$subject = $params->get('update_email_subject');
$eval = $params->get('eval', 0);
$from = $this->config->get('mailfrom');
$fromName = $this->config->get('fromname');
$emailWhich = $this->emailWhich();
foreach ($aids as $id) {
$row = $model->getRow($id, true);
/**
* hugh - hack to work around this issue:
* https://github.com/Fabrik/fabrik/issues/1499
*/
$this->params = $params;
$to = trim($this->emailTo($row, $emailWhich));
$tos = explode(',', $to);
$cleanTo = true;
foreach ($tos as &$email) {
$email = trim($email);
if (!(JMailHelper::cleanAddress($email) && FabrikWorker::isEmail($email))) {
$cleanTo = false;
}
}
if ($cleanTo) {
if (count($tos) > 1) {
$to = $tos;
}
$thisSubject = $w->parseMessageForPlaceholder($subject, $row);
$thisMessage = $w->parseMessageForPlaceholder($message, $row);
if ($eval) {
$thisMessage = @eval($thisMessage);
FabrikWorker::logEval($thisMessage, 'Caught exception on eval in updatecol::process() : %s');
}
$mail = JFactory::getMailer();
$res = $mail->sendMail($from, $fromName, $to, $thisSubject, $thisMessage, true);
if ($res) {
$this->sent++;
} else {
$this->notsent++;
}
} else {
$this->notsent++;
}
}
}
}