本文整理汇总了PHP中Mautic\CoreBundle\Helper\InputHelper::url方法的典型用法代码示例。如果您正苦于以下问题:PHP InputHelper::url方法的具体用法?PHP InputHelper::url怎么用?PHP InputHelper::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mautic\CoreBundle\Helper\InputHelper
的用法示例。
在下文中一共展示了InputHelper::url方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getWebsiteSnapshotAction
/**
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
protected function getWebsiteSnapshotAction(Request $request)
{
$data = ['success' => 0];
if ($this->get('mautic.security')->isGranted('plugin:focus:items:create')) {
$website = InputHelper::url($request->request->get('website'));
if ($website) {
// Let's try to extract colors from image
$id = InputHelper::int($request->request->get('id'));
if (!empty($id)) {
// Tell the JS to not populate with default colors
$data['ignoreDefaultColors'] = true;
}
$snapshotUrl = $this->get('mautic.helper.core_parameters')->getParameter('website_snapshot_url');
$snapshotKey = $this->get('mautic.helper.core_parameters')->getParameter('website_snapshot_key');
$http = $this->get('mautic.http.connector');
$response = $http->get($snapshotUrl . '?url=' . urlencode($website) . '&key=' . $snapshotKey, [], 30);
if ($response->code === 200) {
$package = json_decode($response->body, true);
if (isset($package['images'])) {
$data['image']['desktop'] = $package['images']['desktop'];
$data['image']['mobile'] = $package['images']['mobile'];
$palette = $package['palette'];
$data['colors'] = ['primaryColor' => $palette[0], 'textColor' => FocusModel::isLightColor($palette[0]) ? '#000000' : '#ffffff', 'buttonColor' => $palette[1], 'buttonTextColor' => FocusModel::isLightColor($palette[1]) ? '#000000' : '#ffffff'];
$data['success'] = 1;
}
}
}
}
return $this->sendJsonResponse($data);
}
示例2: sendHookTestAction
protected function sendHookTestAction(Request $request)
{
$url = InputHelper::url($request->request->get('url'));
// validate the URL
if ($url == '' || !$url) {
// default to an error message
$dataArray = array('success' => 1, 'html' => '<div class="has-error"><span class="help-block">' . $this->factory->getTranslator()->trans('mautic.webhook.label.no.url') . '</span></div>');
return $this->sendJsonResponse($dataArray);
}
// get the selected types
$selectedTypes = InputHelper::cleanArray($request->request->get('types'));
$payloadPaths = $this->getPayloadPaths($selectedTypes);
$payloads = $this->loadPayloads($payloadPaths);
$now = new \DateTime();
$payloads['timestamp'] = $now->format('c');
// Set up custom headers
$headers = ['Content-Type' => 'application/json'];
// instantiate new http class
$http = new Http();
// set the response
$response = $http->post($url, json_encode($payloads), $headers);
// default to an error message
$dataArray = array('success' => 1, 'html' => '<div class="has-error"><span class="help-block">' . $this->factory->getTranslator()->trans('mautic.webhook.label.warning') . '</span></div>');
// if we get a 200 response convert to success message
if ($response->code == 200) {
$dataArray['html'] = '<div class="has-success"><span class="help-block">' . $this->factory->getTranslator()->trans('mautic.webhook.label.success') . '</span></div>';
}
return $this->sendJsonResponse($dataArray);
}
示例3: submitAction
/**
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function submitAction()
{
if ($this->request->getMethod() !== 'POST') {
return $this->accessDenied();
}
$post = $this->request->request->get('mauticform');
$messengerMode = !empty($post['messenger']);
$server = $this->request->server->all();
$return = isset($post['return']) ? $post['return'] : false;
if (empty($return)) {
//try to get it from the HTTP_REFERER
$return = isset($server['HTTP_REFERER']) ? $server['HTTP_REFERER'] : false;
}
if (!empty($return)) {
//remove mauticError and mauticMessage from the referer so it doesn't get sent back
$return = InputHelper::url($return, null, null, null, array('mauticError', 'mauticMessage'), true);
$query = strpos($return, '?') === false ? '?' : '&';
}
$translator = $this->get('translator');
if (!isset($post['formId']) && isset($post['formid'])) {
$post['formId'] = $post['formid'];
} elseif (isset($post['formId']) && !isset($post['formid'])) {
$post['formid'] = $post['formId'];
}
//check to ensure there is a formId
if (!isset($post['formId'])) {
$error = $translator->trans('mautic.form.submit.error.unavailable', array(), 'flashes');
} else {
$formModel = $this->factory->getModel('form.form');
$form = $formModel->getEntity($post['formId']);
//check to see that the form was found
if ($form === null) {
$error = $translator->trans('mautic.form.submit.error.unavailable', array(), 'flashes');
} else {
//get what to do immediately after successful post
$postAction = $form->getPostAction();
$postActionProperty = $form->getPostActionProperty();
//check to ensure the form is published
$status = $form->getPublishStatus();
$dateTemplateHelper = $this->get('mautic.helper.template.date');
if ($status == 'pending') {
$error = $translator->trans('mautic.form.submit.error.pending', array('%date%' => $dateTemplateHelper->toFull($form->getPublishUp())), 'flashes');
} elseif ($status == 'expired') {
$error = $translator->trans('mautic.form.submit.error.expired', array('%date%' => $dateTemplateHelper->toFull($form->getPublishDown())), 'flashes');
} elseif ($status != 'published') {
$error = $translator->trans('mautic.form.submit.error.unavailable', array(), 'flashes');
} else {
$result = $this->factory->getModel('form.submission')->saveSubmission($post, $server, $form);
if (!empty($result['errors'])) {
if ($messengerMode) {
$error = $result['errors'];
} else {
$error = $result['errors'] ? $this->get('translator')->trans('mautic.form.submission.errors') . '<br /><ol><li>' . implode("</li><li>", $result['errors']) . '</li></ol>' : false;
}
} elseif (!empty($result['callback'])) {
$callback = $result['callback']['callback'];
if (is_callable($callback)) {
if (is_array($callback)) {
$reflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (strpos($callback, '::') !== false) {
$parts = explode('::', $callback);
$reflection = new \ReflectionMethod($parts[0], $parts[1]);
} else {
$reflection = new \ReflectionMethod(null, $callback);
}
//add the factory to the arguments
$result['callback']['factory'] = $this->factory;
$pass = array();
$result['callback']['messengerMode'] = $messengerMode;
foreach ($reflection->getParameters() as $param) {
if (isset($result['callback'][$param->getName()])) {
$pass[] = $result['callback'][$param->getName()];
} else {
$pass[] = null;
}
}
$callbackResponse = $reflection->invokeArgs($this, $pass);
if (!$messengerMode) {
return $callbackResponse;
}
}
}
}
}
}
if ($messengerMode) {
// Return the call via postMessage API
$data = array('success' => 1);
if (!empty($error)) {
if (is_array($error)) {
$data['validationErrors'] = $error;
} else {
$data['errorMessage'] = $error;
}
$data['success'] = 0;
} else {
if ($postAction == 'redirect') {
//.........这里部分代码省略.........
示例4: saveSubmission
/**
* @param $post
* @param $server
* @param Form $form
*
* @return boolean|string false if no error was encountered; otherwise the error message
*/
public function saveSubmission($post, $server, Form $form)
{
$fieldHelper = new FormFieldHelper($this->translator);
//everything matches up so let's save the results
$submission = new Submission();
$submission->setDateSubmitted(new \DateTime());
$submission->setForm($form);
$ipAddress = $this->factory->getIpAddress();
$submission->setIpAddress($ipAddress);
if (!empty($post['return'])) {
$referer = $post['return'];
} elseif (!empty($server['HTTP_REFERER'])) {
$referer = $server['HTTP_REFERER'];
} else {
$referer = '';
}
//clean the referer by removing mauticError and mauticMessage
$referer = InputHelper::url($referer, null, null, array('mauticError', 'mauticMessage'));
$submission->setReferer($referer);
$fields = $form->getFields();
$fieldArray = array();
$results = array();
$tokens = array();
$leadFieldMatches = array();
$validationErrors = array();
foreach ($fields as $f) {
$id = $f->getId();
$type = $f->getType();
$alias = $f->getAlias();
$value = isset($post[$alias]) ? $post[$alias] : '';
$fieldArray[$id] = array('id' => $id, 'type' => $type, 'alias' => $alias);
if (in_array($type, array('button', 'freetext'))) {
//don't save items that don't have a value associated with it
continue;
} elseif ($type == 'captcha') {
$captcha = $fieldHelper->validateFieldValue($type, $value, $f);
if (!empty($captcha)) {
$props = $f->getProperties();
//check for a custom message
$validationErrors[$alias] = !empty($props['errorMessage']) ? $props['errorMessage'] : implode('<br />', $captcha);
}
continue;
}
if ($f->isRequired() && empty($value)) {
//somehow the user got passed the JS validation
$msg = $f->getValidationMessage();
if (empty($msg)) {
$msg = $this->translator->trans('mautic.form.field.generic.validationfailed', array('%label%' => $f->getLabel()), 'validators');
}
$validationErrors[$alias] = $msg;
continue;
}
//clean and validate the input
if ($f->isCustom()) {
$params = $f->getCustomParameters();
if (!empty($value)) {
if (isset($params['valueFilter'])) {
if (is_string($params['inputFilter'] && method_exists('\\Mautic\\CoreBundle\\Helper\\InputHelper', $params['valueFilter']))) {
$value = InputHelper::_($value, $params['valueFilter']);
} elseif (is_callable($params['valueFilter'])) {
$value = call_user_func_array($params['valueFilter'], array($f, $value));
} else {
$value = InputHelper::_($value, 'clean');
}
} else {
$value = InputHelper::_($value, 'clean');
}
}
if (isset($params['valueConstraints']) && is_callable($params['valueConstraints'])) {
$customErrors = call_user_func_array($params['valueConstraints'], array($f, $value));
if (!empty($customErrors)) {
$validationErrors[$alias] = is_array($customErrors) ? implode('<br />', $customErrors) : $customErrors;
}
}
} elseif (!empty($value)) {
$filter = $fieldHelper->getFieldFilter($type);
$value = InputHelper::_($value, $filter);
$validation = $fieldHelper->validateFieldValue($type, $value);
if (!empty($validation)) {
$validationErrors[$alias] = is_array($validation) ? implode('<br />', $validation) : $validation;
}
}
//convert array from checkbox groups and multiple selects
if (is_array($value)) {
$value = implode(", ", $value);
}
$tokens["{formfield={$alias}}"] = $value;
//save the result
if ($f->getSaveResult() !== false) {
$results[$alias] = $value;
}
$leadField = $f->getLeadField();
if (!empty($leadField)) {
//.........这里部分代码省略.........
示例5: saveSubmission
/**
* @param $post
* @param $server
* @param Form $form
*
* @return bool|array
*/
public function saveSubmission($post, $server, Form $form, Request $request = null, $returnEvent = false)
{
$leadFields = $this->leadFieldModel->getFieldListWithProperties(false);
//everything matches up so let's save the results
$submission = new Submission();
$submission->setDateSubmitted(new \DateTime());
$submission->setForm($form);
//set the landing page the form was submitted from if applicable
if (!empty($post['mauticpage'])) {
$page = $this->pageModel->getEntity((int) $post['mauticpage']);
if ($page != null) {
$submission->setPage($page);
}
}
$ipAddress = $this->ipLookupHelper->getIpAddress();
$submission->setIpAddress($ipAddress);
if (!empty($post['return'])) {
$referer = $post['return'];
} elseif (!empty($server['HTTP_REFERER'])) {
$referer = $server['HTTP_REFERER'];
} else {
$referer = '';
}
//clean the referer by removing mauticError and mauticMessage
$referer = InputHelper::url($referer, null, null, ['mauticError', 'mauticMessage']);
$submission->setReferer($referer);
// Create an event to be dispatched through the processes
$submissionEvent = new SubmissionEvent($submission, $post, $server, $request);
// Get a list of components to build custom fields from
$components = $this->formModel->getCustomComponents();
$fields = $form->getFields();
$fieldArray = [];
$results = [];
$tokens = [];
$leadFieldMatches = [];
$validationErrors = [];
/** @var Field $f */
foreach ($fields as $f) {
$id = $f->getId();
$type = $f->getType();
$alias = $f->getAlias();
$value = isset($post[$alias]) ? $post[$alias] : '';
$fieldArray[$id] = ['id' => $id, 'type' => $type, 'alias' => $alias];
if ($type == 'captcha') {
$captcha = $this->fieldHelper->validateFieldValue($type, $value, $f);
if (!empty($captcha)) {
$props = $f->getProperties();
//check for a custom message
$validationErrors[$alias] = !empty($props['errorMessage']) ? $props['errorMessage'] : implode('<br />', $captcha);
}
continue;
}
if ($f->isRequired() && empty($value)) {
//field is required, but hidden from form because of 'ShowWhenValueExists'
if ($f->getShowWhenValueExists() === false && !isset($post[$alias])) {
continue;
}
//somehow the user got passed the JS validation
$msg = $f->getValidationMessage();
if (empty($msg)) {
$msg = $this->translator->trans('mautic.form.field.generic.validationfailed', ['%label%' => $f->getLabel()], 'validators');
}
$validationErrors[$alias] = $msg;
continue;
}
if (in_array($type, $components['viewOnlyFields'])) {
//don't save items that don't have a value associated with it
continue;
}
//clean and validate the input
if ($f->isCustom()) {
if (!isset($components['fields'][$f->getType()])) {
continue;
}
$params = $components['fields'][$f->getType()];
if (!empty($value)) {
if (isset($params['valueFilter'])) {
if (is_string($params['valueFilter']) && is_callable(['\\Mautic\\CoreBundle\\Helper\\InputHelper', $params['valueFilter']])) {
$value = InputHelper::_($value, $params['valueFilter']);
} elseif (is_callable($params['valueFilter'])) {
$value = call_user_func_array($params['valueFilter'], [$f, $value]);
} else {
$value = InputHelper::_($value, 'clean');
}
} else {
$value = InputHelper::_($value, 'clean');
}
}
// @deprecated - BC support; to be removed in 3.0 - be sure to remove support in FormBuilderEvent as well
if (isset($params['valueConstraints']) && is_callable($params['valueConstraints'])) {
$customErrors = call_user_func_array($params['valueConstraints'], [$f, $value]);
if (!empty($customErrors)) {
$validationErrors[$alias] = is_array($customErrors) ? implode('<br />', $customErrors) : $customErrors;
//.........这里部分代码省略.........
示例6: submitAction
/**
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function submitAction()
{
if ($this->request->getMethod() !== 'POST') {
return $this->accessDenied();
}
$isAjax = $this->request->query->get('ajax', false);
$form = null;
$post = $this->request->request->get('mauticform');
$messengerMode = !empty($post['messenger']);
$server = $this->request->server->all();
$return = isset($post['return']) ? $post['return'] : false;
if (empty($return)) {
//try to get it from the HTTP_REFERER
$return = isset($server['HTTP_REFERER']) ? $server['HTTP_REFERER'] : false;
}
if (!empty($return)) {
//remove mauticError and mauticMessage from the referer so it doesn't get sent back
$return = InputHelper::url($return, null, null, null, ['mauticError', 'mauticMessage'], true);
$query = strpos($return, '?') === false ? '?' : '&';
}
$translator = $this->get('translator');
if (!isset($post['formId']) && isset($post['formid'])) {
$post['formId'] = $post['formid'];
} elseif (isset($post['formId']) && !isset($post['formid'])) {
$post['formid'] = $post['formId'];
}
//check to ensure there is a formId
if (!isset($post['formId'])) {
$error = $translator->trans('mautic.form.submit.error.unavailable', [], 'flashes');
} else {
$formModel = $this->getModel('form.form');
$form = $formModel->getEntity($post['formId']);
//check to see that the form was found
if ($form === null) {
$error = $translator->trans('mautic.form.submit.error.unavailable', [], 'flashes');
} else {
//get what to do immediately after successful post
$postAction = $form->getPostAction();
$postActionProperty = $form->getPostActionProperty();
//check to ensure the form is published
$status = $form->getPublishStatus();
$dateTemplateHelper = $this->get('mautic.helper.template.date');
if ($status == 'pending') {
$error = $translator->trans('mautic.form.submit.error.pending', ['%date%' => $dateTemplateHelper->toFull($form->getPublishUp())], 'flashes');
} elseif ($status == 'expired') {
$error = $translator->trans('mautic.form.submit.error.expired', ['%date%' => $dateTemplateHelper->toFull($form->getPublishDown())], 'flashes');
} elseif ($status != 'published') {
$error = $translator->trans('mautic.form.submit.error.unavailable', [], 'flashes');
} else {
$result = $this->getModel('form.submission')->saveSubmission($post, $server, $form, $this->request, true);
if (!empty($result['errors'])) {
if ($messengerMode || $isAjax) {
$error = $result['errors'];
} else {
$error = $result['errors'] ? $this->get('translator')->trans('mautic.form.submission.errors') . '<br /><ol><li>' . implode('</li><li>', $result['errors']) . '</li></ol>' : false;
}
} elseif (!empty($result['callback'])) {
/** @var SubmissionEvent $submissionEvent */
$submissionEvent = $result['callback'];
// Return the first Response object if one is defined
$firstResponseObject = false;
if ($callbackResponses = $submissionEvent->getPostSubmitCallbackResponse()) {
// Some submit actions already injected it's responses
foreach ($callbackResponses as $key => $response) {
if ($response instanceof Response) {
$firstResponseObject = $key;
break;
}
}
}
// These submit actions have requested a callback after all is said and done
$callbacksRequested = $submissionEvent->getPostSubmitCallback();
foreach ($callbacksRequested as $key => $callbackRequested) {
$callbackRequested['messengerMode'] = $messengerMode;
$callbackRequested['ajaxMode'] = $isAjax;
if (isset($callbackRequested['eventName'])) {
$submissionEvent->setPostSubmitCallback($key, $callbackRequested);
$this->get('event_dispatcher')->dispatch($callbackRequested['eventName'], $submissionEvent);
} elseif (isset($callbackRequested['callback'])) {
// @deprecated - to be removed in 3.0; use eventName instead - be sure to remove callback key support from SubmissionEvent::setPostSubmitCallback
$callback = $callbackRequested['callback'];
if (is_callable($callback)) {
if (is_array($callback)) {
$reflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (strpos($callback, '::') !== false) {
$parts = explode('::', $callback);
$reflection = new \ReflectionMethod($parts[0], $parts[1]);
} else {
$reflection = new \ReflectionMethod(null, $callback);
}
//add the factory to the arguments
$callbackRequested['factory'] = $this->factory;
$pass = [];
foreach ($reflection->getParameters() as $param) {
if (isset($callbackRequested[$param->getName()])) {
$pass[] = $callbackRequested[$param->getName()];
} else {
//.........这里部分代码省略.........