本文整理汇总了PHP中ArrayHelper::stringToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::stringToArray方法的具体用法?PHP ArrayHelper::stringToArray怎么用?PHP ArrayHelper::stringToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::stringToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMessage
/**
* Sends an email submitted through a contact form.
*
* @param ContactFormModel $message
* @throws Exception
* @return bool
*/
public function sendMessage(ContactFormModel $message)
{
$settings = craft()->plugins->getPlugin('contactform')->getSettings();
if (!$settings->toEmail) {
throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
}
// Fire an 'onBeforeSend' event
Craft::import('plugins.contactform.events.ContactFormEvent');
$event = new ContactFormEvent($this, array('message' => $message));
$this->onBeforeSend($event);
if ($event->isValid) {
if (!$event->fakeIt) {
$toEmails = ArrayHelper::stringToArray($settings->toEmail);
foreach ($toEmails as $toEmail) {
$email = new EmailModel();
$emailSettings = craft()->email->getSettings();
$email->fromEmail = $emailSettings['emailAddress'];
$email->replyTo = $message->fromEmail;
$email->sender = $emailSettings['emailAddress'];
$email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
$email->toEmail = $toEmail;
$email->subject = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
$email->body = $message->message;
if ($message->attachment) {
$email->addAttachment($message->attachment->getTempName(), $message->attachment->getName(), 'base64', $message->attachment->getType());
}
craft()->email->sendEmail($email);
}
}
return true;
}
return false;
}
示例2: getRecipients
/**
* @param mixed|null $element
*
* @throws \Exception
* @return array|string
*/
public function getRecipients($element = null)
{
$recipientsString = $this->getAttribute('recipients');
// Possibly called from entry edit screen
if (is_null($element)) {
return $recipientsString;
}
// Previously converted to array somehow?
if (is_array($recipientsString)) {
return $recipientsString;
}
// Previously stored as JSON string?
if (stripos($recipientsString, '[') === 0) {
return JsonHelper::decode($recipientsString);
}
// Still a string with possible twig generator code?
if (stripos($recipientsString, '{') !== false) {
try {
$recipients = craft()->templates->renderObjectTemplate($recipientsString, $element);
return array_unique(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($recipients)));
} catch (\Exception $e) {
throw $e;
}
}
// Just a regular CSV list
if (!empty($recipientsString)) {
return ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($recipientsString));
}
return array();
}
示例3: prepValue
/**
* @inheritDoc IFieldType::prepValue()
*
* @param mixed $value
*
* @return mixed
*/
public function prepValue($value)
{
$selectedValues = ArrayHelper::stringToArray($value);
if ($this->multi) {
if (is_array($value)) {
// Convert all the values to OptionData objects
foreach ($value as &$val) {
$label = $this->getOptionLabel($val);
$val = new OptionData($label, $val, true);
}
} else {
$value = array();
}
$value = new MultiOptionsFieldData($value);
} else {
// Convert the value to a SingleOptionFieldData object
$label = $this->getOptionLabel($value);
$value = new SingleOptionFieldData($label, $value, true);
}
$options = array();
foreach ($this->getOptions() as $option) {
$selected = in_array($option['value'], $selectedValues);
$options[] = new OptionData($option['label'], $option['value'], $selected);
}
$value->setOptions($options);
return $value;
}
示例4: setAttribute
/**
* Sets an attribute's value.
*
* @param string $name
* @param mixed $value
* @return bool
*/
public function setAttribute($name, $value)
{
// Set packages as an array
if ($name == 'packages' && !is_array($value)) {
if ($value) {
$value = array_filter(ArrayHelper::stringToArray($value));
sort($value);
} else {
$value = array();
}
}
return parent::setAttribute($name, $value);
}
示例5: fetched
/**
* Returns an array of pre-fetched related elements, optionally restricted by one or more
* relations field handles.
*
* @param array|null $fieldHandles
*
* @return array
*/
public function fetched($fieldHandles = null)
{
$elements = array();
if ($fieldHandles) {
$fieldHandles = ArrayHelper::stringToArray($fieldHandles);
} else {
$fieldHandles = array_keys($this->_elementsByFieldHandle);
}
foreach ($fieldHandles as $fieldHandle) {
if (array_key_exists($fieldHandle, $this->_elementsByFieldHandle)) {
$elements = array_merge($elements, $this->_elementsByFieldHandle[$fieldHandle]);
}
}
return $elements;
}
示例6: sendMessage
/**
* Sends an email submitted through a contact form.
*
* @param ContactFormModel $message
* @throws Exception
* @return bool
*/
public function sendMessage(ContactFormModel $message)
{
$settings = craft()->plugins->getPlugin('contactform')->getSettings();
if (!$settings->toEmail) {
throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
}
// Fire an 'onBeforeSend' event
Craft::import('plugins.contactform.events.ContactFormEvent');
$event = new ContactFormEvent($this, array('message' => $message));
$this->onBeforeSend($event);
if ($event->isValid) {
if (!$event->fakeIt) {
// Grab any "to" emails set in the plugin settings.
$toEmails = ArrayHelper::stringToArray($settings->toEmail);
foreach ($toEmails as $toEmail) {
$variables = array();
$email = new EmailModel();
$emailSettings = craft()->email->getSettings();
$email->fromEmail = $emailSettings['emailAddress'];
$email->replyTo = $message->fromEmail;
$email->sender = $emailSettings['emailAddress'];
$email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
$email->toEmail = $toEmail;
$email->subject = '{{ emailSubject }}';
$email->body = '{{ emailBody }}';
$variables['emailSubject'] = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
$variables['emailBody'] = $message->message;
if (!empty($message->htmlMessage)) {
// Prevent Twig tags from getting parsed
$email->htmlBody = str_replace(array('{', '}'), array('{', '}'), $message->htmlMessage);
}
if (!empty($message->attachment)) {
foreach ($message->attachment as $attachment) {
if ($attachment) {
$email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType());
}
}
}
craft()->email->sendEmail($email, $variables);
}
}
return true;
}
return false;
}
示例7: sendMessage
/**
* Sends an email submitted through a contact form.
*
* @param ContactFormModel $message
* @throws Exception
* @return bool
*/
public function sendMessage(ContactFormModel $message)
{
$settings = craft()->plugins->getPlugin('contactform')->getSettings();
// Fire an 'onBeforeSend' event
Craft::import('plugins.contactform.events.ContactFormEvent');
$event = new ContactFormEvent($this, array('message' => $message));
$this->onBeforeSend($event);
if ($event->isValid) {
if (!$event->fakeIt) {
// Get the relevant email address(es) for the message subject
foreach ($settings->toEmail as $row) {
if ($message->subject == $row['subject']) {
if (!$row['email']) {
throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
}
$toEmails = ArrayHelper::stringToArray($row['email']);
}
}
foreach ($toEmails as $toEmail) {
$email = new EmailModel();
$emailSettings = craft()->email->getSettings();
$email->fromEmail = $emailSettings['emailAddress'];
$email->replyTo = $message->fromEmail;
$email->sender = $emailSettings['emailAddress'];
$email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
$email->toEmail = $toEmail;
$email->subject = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
$email->body = "An email has been sent by {$message->fromName} ({$message->fromEmail}) using the contact form on the website. Here is the message:\n\n" . $message->message;
if (!empty($message->attachment)) {
foreach ($message->attachment as $attachment) {
if ($attachment) {
$email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType());
}
}
}
craft()->email->sendEmail($email);
}
}
return true;
}
return false;
}
示例8: elements
/**
* Returns an array of {$elementType}Model instances related to the
* elements passed in as the second parameter.
*
* You can optionally restrict the results to particular fields, and override the source
* locale.
*
* @since 0.1.0
*
* @param array $elementType The element type for the relation
* @param array $sourceElements An array of source elements
* @param string|array|null $fieldHandles An optional string or array of field handles
* @param string|null $sourceLocale An optional locale ID
*
* @return array An array of BaseElementModel instances, populated from the results
*/
public function elements($elementType, array &$sourceElements, $fieldHandles = null, $sourceLocale = null)
{
$sourceElementsById = array();
$targetIds = array();
// Cast the field handles to an array
$fieldHandles = ArrayHelper::stringToArray($fieldHandles);
// reorder the source elements by ID
foreach ($sourceElements as $sourceElement) {
$sourceElementsById[$sourceElement->id] = $sourceElement;
}
// Attach the behavior to each of the source elements
foreach ($sourceElementsById as $sourceElement) {
if (!$sourceElement->asa('fetched_elements')) {
$sourceElement->attachBehavior('fetched_elements', new Fetch_FetchedElementsBehavior());
}
}
// Perform the first query to get the information from the craft_relations table
$relations = $this->_getRelations($sourceElementsById, $fieldHandles, $sourceLocale);
// Collect the targetIds so we can fetch all the elements in one go later on
$targetIds = array_map(function ($relation) {
return $relation['fetchTargetId'];
}, $relations);
// Perform the second query to fetch all the related elements by their IDs
$elements = craft()->elements->getCriteria($elementType)->id($targetIds)->indexBy('id')->locale($sourceLocale)->limit(null)->find();
// Add each related element to its source element, using the Fetch_FetchedElementsBehavior
foreach ($relations as &$relation) {
$sourceId = $relation['fetchSourceId'];
$fieldHandle = $relation['handle'];
$targetId = $relation['fetchTargetId'];
$sortOrder = (int) $relation['sortOrder'] - 1;
$sourceElementsById[$sourceId]->addFetchedElement($elements[$targetId], $fieldHandle, $sortOrder);
unset($sourceId, $fieldHandle, $targetId, $sourceOrder, $relation);
}
// Return the modified entries in their original order
foreach ($sourceElements as &$sourceElement) {
$sourceElement = $sourceElementsById[$sourceElement->id];
unset($sourceElementsById[$sourceElement->id]);
}
return $sourceElements;
}
示例9: validateOptions
/**
* Returns whether or not the user meets the criteria necessary to trigger the event
*
* @param mixed $options
* @param UserModel $user
* @param array $params
*
* @return bool
*/
public function validateOptions($options, UserModel $user, array $params = array())
{
$isNewUser = isset($params['isNewUser']) && $params['isNewUser'];
$whenNew = isset($options['craft']['saveUser']['whenNew']) && $options['craft']['saveUser']['whenNew'];
$whenUpdated = isset($options['craft']['saveUser']['whenUpdated']) && $options['craft']['saveUser']['whenUpdated'];
SproutEmailPlugin::log(Craft::t("Sprout Email '" . $this->getTitle() . "' event has been triggered"));
// If any user groups were checked, make sure the user is in one of the groups
if (!empty($options['craft']['saveUser']['userGroupIds']) && count($options['craft']['saveUser']['userGroupIds'])) {
$inGroup = false;
$existingUserGroups = $user->getGroups('id');
// When saving a new user, we grab our groups from the post request
// because _processUserGroupsPermissions() runs after saveUser()
$newUserGroups = craft()->request->getPost('groups');
if (!is_array($newUserGroups)) {
$newUserGroups = ArrayHelper::stringToArray($newUserGroups);
}
foreach ($options['craft']['saveUser']['userGroupIds'] as $groupId) {
if (array_key_exists($groupId, $existingUserGroups) || in_array($groupId, $newUserGroups)) {
$inGroup = true;
}
}
if (!$inGroup) {
SproutEmailPlugin::log(Craft::t('Saved user not in any selected User Group.'));
return false;
}
}
if (!$whenNew && !$whenUpdated) {
SproutEmailPlugin::log(Craft::t("No settings have been selected. Please select 'When a user is created' or 'When\n\t\t\ta user is updated' from the options on the Rules tab."));
return false;
}
if ($whenNew && !$isNewUser && !$whenUpdated) {
SproutEmailPlugin::log(Craft::t("No match. 'When a user is created' is selected but the user is being updated."));
return false;
}
if ($whenUpdated && $isNewUser && !$whenNew) {
SproutEmailPlugin::log(Craft::t("No match. 'When a user is updated' is selected but the user is new."));
return false;
}
return true;
}
示例10: sendLog
/**
* Send log.
*
* @return bool
*/
public function sendLog()
{
// Get email address
$recipients = craft()->amSeed_settings->getSettingsByHandleAndType('emailAddressForLogs', AmSeedModel::SettingGeneral);
if ($recipients && $recipients->value) {
$recipients = $recipients->value;
} else {
return false;
}
// Check for multiple recipients
$recipients = ArrayHelper::stringToArray($recipients);
$recipients = array_unique($recipients);
if (!count($recipients)) {
return false;
}
// Craft email settings
$settings = craft()->email->getSettings();
$systemEmail = !empty($settings['emailAddress']) ? $settings['emailAddress'] : '';
$systemName = !empty($settings['senderName']) ? $settings['senderName'] : '';
// Set email settings
$success = false;
$email = new EmailModel();
$email->htmlBody = '<pre>' . print_r($this->_log, true) . '</pre>';
$email->fromEmail = $systemEmail;
$email->fromName = $systemName;
$email->subject = Craft::t('Dummy generation log');
// Send emails
foreach ($recipients as $recipient) {
$email->toEmail = $recipient;
if (filter_var($email->toEmail, FILTER_VALIDATE_EMAIL)) {
// Add variable for email event
if (craft()->email->sendEmail($email)) {
$success = true;
}
}
}
return $success;
}
示例11: sendMessage
public function sendMessage(ContactForm_MessageModel $message)
{
$settings = craft()->plugins->getPlugin('contactform')->getSettings();
if (!$settings->toEmail) {
throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
}
if (!$settings->fromEmail) {
throw new Exception('The "From Email" address is not set on the plugin’s settings page.');
}
$this->validateMessage($message);
if ($this->isValid) {
if (!$this->fakeIt) {
// Grab any "to" emails set in the plugin settings.
$toEmails = ArrayHelper::stringToArray($settings->toEmail);
foreach ($toEmails as $toEmail) {
$email = new EmailModel();
$emailSettings = craft()->email->getSettings();
$email->fromEmail = $settings->fromEmail;
$email->replyTo = $message->email;
$email->sender = $emailSettings['emailAddress'];
$email->fromName = $settings->prependSender . ($settings->prependSender && $message->name ? ' ' : '') . $message->name;
$email->toEmail = $toEmail;
$email->subject = $settings->subject;
$email->body = $message->message;
if (!empty($message->attachment)) {
foreach ($message->attachment as $attachment) {
if ($attachment) {
$email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType());
}
}
}
craft()->email->sendEmail($email);
}
}
return true;
}
return false;
}
示例12: sendEmailNotification
/**
* Send Email Notification
*
*/
public function sendEmailNotification($form, $postUploads, $message, $html = true, $email = null)
{
$errors = false;
$attributes = $form->getAttributes();
$notificationSettings = $attributes['notificationSettings'];
$toEmails = ArrayHelper::stringToArray($notificationSettings['emailSettings']['notifyEmail']);
foreach ($toEmails as $toEmail) {
$email = new EmailModel();
$emailSettings = craft()->email->getSettings();
$email->fromEmail = $emailSettings['emailAddress'];
$email->replyTo = $emailSettings['emailAddress'];
$email->sender = $emailSettings['emailAddress'];
$email->fromName = $form->name;
$email->toEmail = $toEmail;
$email->subject = $notificationSettings['emailSettings']['emailSubject'];
$email->body = $message;
// TODO: Add attachments to emails
// if ($postUploads) {
// foreach ($postUploads as $key => $value) {
// $file = \CUploadedFile::getInstanceByName($key);
// $email->addAttachment($file->getTempName(), $file->getName(), 'base64', $file->getType());
// }
// }
if (!craft()->email->sendEmail($email)) {
$errors = true;
}
}
return $errors ? false : true;
}
示例13: getOnTheFlyRecipients
/**
* @return array
*/
protected function getOnTheFlyRecipients()
{
$postedRecipients = craft()->request->getPost('recipient.onTheFlyRecipients');
return array_filter(array_map('trim', ArrayHelper::stringToArray($postedRecipients)));
}
示例14: buildEventsQuery
/**
* Preps a {@link DbCommand} object for querying for elements, based on a given element criteria.
*
* @param Venti_CriteriaModel &$criteria The events criteria model
*
* @return DbCommand|false The DbCommand object, or `false` if the method was able to determine ahead of time that
* there’s no chance any elements are going to be found with the given parameters.
*/
public function buildEventsQuery(Venti_CriteriaModel $criteria)
{
$elementType = $criteria->getElementType();
if (!$elementType->isLocalized()) {
// The criteria *must* be set to the primary locale
$criteria->locale = craft()->i18n->getPrimarySiteLocaleId();
} else {
if (!$criteria->locale) {
// Default to the current app locale
$criteria->locale = craft()->language;
}
}
$query = craft()->db->createCommand()->select('venti.startDate, venti.endDate, venti.allDay, venti.isrepeat, venti.eid, venti.eventid, venti.repeat, venti.rRule, venti.summary, elements.id, elements.type, elements.enabled, elements.archived, elements.dateCreated, elements.dateUpdated, elements_i18n.slug, elements_i18n.uri, elements_i18n.enabled AS localeEnabled')->from('venti_events venti')->join('elements elements', 'elements.id = venti.eventid')->join('elements_i18n elements_i18n', 'elements_i18n.elementId = venti.eventid')->where('elements_i18n.locale = :locale', array(':locale' => $criteria->locale))->limit($criteria->limit)->offset($criteria->offset)->order($criteria->order);
if ($elementType->hasContent()) {
$contentTable = 'content';
if ($contentTable) {
$contentCols = 'content.id AS contentId';
if ($elementType->hasTitles()) {
$contentCols .= ', content.title';
}
$fieldColumns = $this->getContentFieldColumnsForElementsQuery($criteria);
foreach ($fieldColumns as $column) {
$contentCols .= ', content.' . $column['column'];
}
$query->addSelect($contentCols);
$query->join($contentTable . ' content', 'content.elementId = elements.id');
$query->andWhere('content.locale = :locale');
}
}
if ($elementType->hasTitles() && $criteria->title) {
$query->andWhere(DbHelper::parseParam('content.title', $criteria->title, $query->params));
}
if ($criteria->id) {
$query->andWhere(DbHelper::parseParam('venti.eventid', $criteria->id, $query->params));
}
if ($criteria->eid) {
$query->andWhere(DbHelper::parseParam('venti.eid', $criteria->eid, $query->params));
}
if ($criteria->isrepeat) {
$query->andWhere(DbHelper::parseParam('venti.isrepeat', $criteria->isrepeat, $query->params));
}
if ($criteria->startDate) {
$query->andWhere(DbHelper::parseDateParam('venti.startDate', $criteria->startDate, $query->params));
}
if ($criteria->endDate) {
$query->andWhere(DbHelper::parseDateParam('venti.endDate', $criteria->endDate, $query->params));
}
if ($criteria->summary) {
$query->andWhere(DbHelper::parseParam('venti.summary', $criteria->summary, $query->params));
}
if ($criteria->slug) {
$query->andWhere(DbHelper::parseParam('elements_i18n.slug', $criteria->slug, $query->params));
}
if ($criteria->uri) {
$query->andWhere(DbHelper::parseParam('elements_i18n.uri', $criteria->uri, $query->params));
}
if ($criteria->localeEnabled) {
$query->andWhere('elements_i18n.enabled = 1');
}
if ($criteria->dateCreated) {
$query->andWhere(DbHelper::parseDateParam('elements.dateCreated', $criteria->dateCreated, $query->params));
}
if ($criteria->dateUpdated) {
$query->andWhere(DbHelper::parseDateParam('elements.dateUpdated', $criteria->dateUpdated, $query->params));
}
if ($criteria->archived) {
$query->andWhere('elements.archived = 1');
} else {
$query->andWhere('elements.archived = 0');
if ($criteria->status) {
$statusConditions = array();
$statuses = ArrayHelper::stringToArray($criteria->status);
foreach ($statuses as $status) {
$status = StringHelper::toLowerCase($status);
// Is this a supported status?
if (in_array($status, array_keys($this->getStatuses()))) {
if ($status == BaseElementModel::ENABLED) {
$statusConditions[] = 'elements.enabled = 1';
} else {
if ($status == BaseElementModel::DISABLED) {
$statusConditions[] = 'elements.enabled = 0';
} else {
$elementStatusCondition = $this->getElementQueryStatusCondition($query, $status);
if ($elementStatusCondition) {
$statusConditions[] = $elementStatusCondition;
} else {
if ($elementStatusCondition === false) {
return false;
}
}
}
}
//.........这里部分代码省略.........
示例15: getHeadersToParse
/**
* Ensures that a valid list of parseable headers is returned
*
* @param string $headerString
*
* @return array
*/
public function getHeadersToParse($headerString = '')
{
$allowedHeaders = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
$headers = ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($headerString));
if (count($headers)) {
foreach ($headers as $key => $header) {
$header = strtolower($header);
if (!in_array($header, $allowedHeaders)) {
unset($headers[$key]);
}
}
}
return $headers;
}