/** * {@inheritdoc} * * @param $entity * @param $unlock * @return mixed */ public function saveEntity($entity, $unlock = true) { $alias = $entity->getAlias(); if (empty($alias)) { $alias = strtolower(InputHelper::alphanum($entity->getTitle(), false, '-')); } else { $alias = strtolower(InputHelper::alphanum($alias, false, '-')); } //make sure alias is not already taken $repo = $this->getRepository(); $testAlias = $alias; $bundle = $entity->getBundle(); $count = $repo->checkUniqueCategoryAlias($bundle, $testAlias, $entity); $aliasTag = $count; while ($count) { $testAlias = $alias . $aliasTag; $count = $repo->checkUniqueCategoryAlias($bundle, $testAlias, $entity); $aliasTag++; } if ($testAlias != $alias) { $alias = $testAlias; } $entity->setAlias($alias); parent::saveEntity($entity, $unlock); }
/** * @param FormEvent $event */ public function preSubmitData(FormEvent $event) { $data = $event->getData(); //clean the data $data = InputHelper::_($data, $this->masks); $event->setData($data); }
/** * @param Request $request * @param $modelName * @param $abSettingsFormName * @param $parentFormName * @param $abFormTemplate * @param array $formThemes * * @return mixed */ private function getAbTestForm(Request $request, $modelName, $abSettingsFormName, $parentFormName, $abFormTemplate, $formThemes = []) { $dataArray = ['success' => 0, 'html' => '']; $type = InputHelper::clean($request->request->get('abKey')); $id = InputHelper::int($request->request->get('id')); if (!empty($type)) { //get the HTML for the form $model = $this->getModel($modelName); $entity = $model->getEntity($id); $abTestComponents = $model->getBuilderComponents($entity, 'abTestWinnerCriteria'); $abTestSettings = $abTestComponents['criteria']; if (isset($abTestSettings[$type])) { $html = ''; $formType = !empty($abTestSettings[$type]['formType']) ? $abTestSettings[$type]['formType'] : ''; if (!empty($formType)) { $formOptions = !empty($abTestSettings[$type]['formTypeOptions']) ? $abTestSettings[$type]['formTypeOptions'] : []; $form = $this->get('form.factory')->create($abSettingsFormName, [], ['formType' => $formType, 'formTypeOptions' => $formOptions]); $html = $this->renderView($abFormTemplate, ['form' => $this->setFormTheme($form, $formThemes)]); } $html = str_replace(["{$abSettingsFormName}[", "{$abSettingsFormName}_", $abSettingsFormName], ["{$parentFormName}[variantSettings][", "{$parentFormName}_variantSettings_", $parentFormName], $html); $dataArray['html'] = $html; $dataArray['success'] = 1; } } return $this->sendJsonResponse($dataArray); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function getActionFormAction(Request $request) { $dataArray = ['success' => 0, 'html' => '']; $type = InputHelper::clean($request->request->get('actionType')); if (!empty($type)) { //get the HTML for the form /** @var \Mautic\PointBundle\Model\PointModel $model */ $model = $this->getModel('point'); $actions = $model->getPointActions(); if (isset($actions['actions'][$type])) { $themes = ['MauticPointBundle:FormTheme\\Action']; if (!empty($actions['actions'][$type]['formTheme'])) { $themes[] = $actions['actions'][$type]['formTheme']; } $formType = !empty($actions['actions'][$type]['formType']) ? $actions['actions'][$type]['formType'] : 'genericpoint_settings'; $formTypeOptions = !empty($actions['actions'][$type]['formTypeOptions']) ? $actions['actions'][$type]['formTypeOptions'] : []; $form = $this->get('form.factory')->create('pointaction', [], ['formType' => $formType, 'formTypeOptions' => $formTypeOptions]); $html = $this->renderView('MauticPointBundle:Point:actionform.html.php', ['form' => $this->setFormTheme($form, 'MauticPointBundle:Point:actionform.html.php', $themes)]); //replace pointaction with point $html = str_replace('pointaction', 'point', $html); $dataArray['html'] = $html; $dataArray['success'] = 1; } } return $this->sendJsonResponse($dataArray); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function setBuilderContentAction(Request $request) { $dataArray = array('success' => 0); $entityId = InputHelper::clean($request->request->get('entity')); $session = $this->factory->getSession(); if (!empty($entityId)) { $sessionVar = 'mautic.pagebuilder.' . $entityId . '.content'; // Check for an array of slots $slots = InputHelper::_($request->request->get('slots', array(), true), 'html'); $content = $session->get($sessionVar, array()); if (!is_array($content)) { $content = array(); } if (!empty($slots)) { // Builder was closed so save each content foreach ($slots as $slot => $newContent) { $content[$slot] = $newContent; } $session->set($sessionVar, $content); $dataArray['success'] = 1; } else { // Check for a single slot $newContent = InputHelper::html($request->request->get('content')); $slot = InputHelper::clean($request->request->get('slot')); if (!empty($slot)) { $content[$slot] = $newContent; $session->set($sessionVar, $content); $dataArray['success'] = 1; } } } return $this->sendJsonResponse($dataArray); }
/** * {@inheritdoc} * * @param $entity * @param bool $unlock * @return mixed|void */ public function saveEntity($entity, $unlock = true) { $isNew = $entity->getId() ? false : true; //set some defaults $this->setTimestamps($entity, $isNew, $unlock); $alias = $entity->getAlias(); if (empty($alias)) { $alias = strtolower(InputHelper::alphanum($entity->getName(), false, '-')); } else { $alias = strtolower(InputHelper::alphanum($alias, false, '-')); } //make sure alias is not already taken $repo = $this->getRepository(); $testAlias = $alias; $user = $this->factory->getUser(); $existing = $repo->getLists($user, $testAlias, $entity->getId()); $count = count($existing); $aliasTag = $count; while ($count) { $testAlias = $alias . $aliasTag; $existing = $repo->getLists($user, $testAlias, $entity->getId()); $count = count($existing); $aliasTag++; } if ($testAlias != $alias) { $alias = $testAlias; } $entity->setAlias($alias); $event = $this->dispatchEvent("pre_save", $entity, $isNew); $repo->saveEntity($entity); $this->dispatchEvent("post_save", $entity, $isNew, $event); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function saveApiKeyAction(Request $request) { $apiKey = InputHelper::clean($request->request->get('apiKey')); $dataArray = ['success' => 0]; /** @var \Mautic\InstallBundle\Configurator\Configurator $configurator */ $configurator = $this->get('mautic.configurator'); if ($configurator->isFileWritable()) { try { $cronfigConfig = array('api_key' => $apiKey); // Ensure the config has a secret key $params = $configurator->getParameters(); if (!isset($params['cronfig']) || empty($params['cronfig']['secret_key'])) { $cronfigConfig['secret_key'] = EncryptionHelper::generateKey(); $dataArray['secret_key'] = $cronfigConfig['secret_key']; } // Save the API key only if it doesn't exist or has changed if (!isset($params['cronfig']['api_key']) || !isset($params['cronfig']['secret_key']) || isset($params['cronfig']['api_key']) && $params['cronfig']['api_key'] == $apiKey || isset($params['cronfig']['secret_key']) && $params['cronfig']['secret_key'] == $apiKey) { $configurator->mergeParameters(array('cronfig' => $cronfigConfig)); $configurator->write(); $dataArray['success'] = 1; // We must clear the application cache for the updated values to take effect /** @var \Mautic\CoreBundle\Helper\CacheHelper $cacheHelper */ $cacheHelper = $this->factory->getHelper('cache'); $cacheHelper->clearContainerFile(); } } catch (\RuntimeException $exception) { $this->addFlash('mautic.config.config.error.not.updated', ['%exception%' => $exception->getMessage()], 'error'); } } else { $form->addError(new FormError($this->factory->getTranslator()->trans('mautic.config.notwritable'))); } return $this->sendJsonResponse($dataArray); }
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); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function setIntegrationFilterAction(Request $request) { $session = $this->factory->getSession(); $pluginFilter = InputHelper::int($this->request->get('plugin')); $session->set('mautic.integrations.filter', $pluginFilter); return $this->sendJsonResponse(array('success' => 1)); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function getAbTestFormAction(Request $request) { $dataArray = array('success' => 0, 'html' => ''); $type = InputHelper::clean($request->request->get('abKey')); $emailId = InputHelper::int($request->request->get('emailId')); if (!empty($type)) { //get the HTML for the form /** @var \Mautic\EmailBundle\Model\EmailModel $model */ $model = $this->factory->getModel('email'); $email = $model->getEntity($emailId); $abTestComponents = $model->getBuilderComponents($email, 'abTestWinnerCriteria'); $abTestSettings = $abTestComponents['criteria']; if (isset($abTestSettings[$type])) { $html = ''; $formType = !empty($abTestSettings[$type]['formType']) ? $abTestSettings[$type]['formType'] : ''; if (!empty($formType)) { $formOptions = !empty($abTestSettings[$type]['formTypeOptions']) ? $abTestSettings[$type]['formTypeOptions'] : array(); $form = $this->get('form.factory')->create('email_abtest_settings', array(), array('formType' => $formType, 'formTypeOptions' => $formOptions)); $html = $this->renderView('MauticEmailBundle:AbTest:form.html.php', array('form' => $this->setFormTheme($form, 'MauticEmailBundle:AbTest:form.html.php', 'MauticEmailBundle:FormTheme\\Email'))); } $html = str_replace(array('email_abtest_settings[', 'email_abtest_settings_', 'email_abtest_settings'), array('emailform[variantSettings][', 'emailform_variantSettings_', 'emailform'), $html); $dataArray['html'] = $html; $dataArray['success'] = 1; } } return $this->sendJsonResponse($dataArray); }
/** * @return JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function indexAction() { //set some permissions $permissions = $this->factory->getSecurity()->isGranted(['core:themes:view', 'core:themes:create', 'core:themes:edit', 'core:themes:delete'], "RETURN_ARRAY"); if (!$permissions['core:themes:view']) { return $this->accessDenied(); } $themeHelper = $this->container->get('mautic.helper.theme'); $dir = $this->factory->getSystemPath('themes', true); $action = $this->generateUrl('mautic_themes_index'); $form = $this->get('form.factory')->create('theme_upload', [], ['action' => $action]); if ($this->request->getMethod() == 'POST') { if (isset($form) && !($cancelled = $this->isFormCancelled($form))) { if ($this->isFormValid($form)) { $fileData = $form['file']->getData(); $fileName = InputHelper::filename($fileData->getClientOriginalName()); $themeName = basename($fileName, '.zip'); if (in_array($themeName, $this->defaultThemes)) { $form->addError(new FormError($this->factory->getTranslator()->trans('mautic.core.theme.default.cannot.overwrite', ['%name%' => $themeName], 'validators'))); } elseif (!empty($fileData)) { try { $fileData->move($dir, $fileName); $themeHelper->install($dir . '/' . $fileName); $this->addFlash('mautic.core.theme.installed', ['%name%' => $themeName]); } catch (\Exception $e) { $form->addError(new FormError($this->factory->getTranslator()->trans($e->getMessage(), [], 'validators'))); } } else { $form->addError(new FormError($this->factory->getTranslator()->trans('mautic.dashboard.upload.filenotfound', [], 'validators'))); } } } } return $this->delegateView(['viewParameters' => ['items' => $themeHelper->getInstalledThemes('all', true, true), 'defaultThemes' => $this->defaultThemes, 'form' => $form->createView(), 'permissions' => $permissions, 'security' => $this->factory->getSecurity()], 'contentTemplate' => 'MauticCoreBundle:Theme:list.html.php', 'passthroughVars' => ['activeLink' => '#mautic_themes_index', 'mauticContent' => 'theme', 'route' => $this->generateUrl('mautic_themes_index')]]); }
/** * {@inheritdoc} */ public function saveEntity($entity, $unlock = true) { if (empty($this->inConversion)) { $alias = $entity->getAlias(); if (empty($alias)) { $alias = strtolower(InputHelper::alphanum($entity->getTitle(), false, '-')); } else { $alias = strtolower(InputHelper::alphanum($alias, false, '-')); } //make sure alias is not already taken $repo = $this->getRepository(); $testAlias = $alias; $count = $repo->checkUniqueAlias($testAlias, $entity); $aliasTag = $count; while ($count) { $testAlias = $alias . $aliasTag; $count = $repo->checkUniqueAlias($testAlias, $entity); $aliasTag++; } if ($testAlias != $alias) { $alias = $testAlias; } $entity->setAlias($alias); } //set the author for new asset if (!$entity->isNew()) { //increase the revision $revision = $entity->getRevision(); $revision++; $entity->setRevision($revision); } parent::saveEntity($entity, $unlock); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function getActionFormAction(Request $request) { $dataArray = array('success' => 0, 'html' => ''); $type = InputHelper::clean($request->request->get('actionType')); if (!empty($type)) { //get the HTML for the form /** @var \Mautic\StageBundle\Model\StageModel $model */ $model = $this->getModel('stage'); $actions = $model->getStageActions(); if (isset($actions['actions'][$type])) { $themes = array('MauticStageBundle:FormTheme\\Action'); if (!empty($actions['actions'][$type]['formTheme'])) { $themes[] = $actions['actions'][$type]['formTheme']; } $formType = !empty($actions['actions'][$type]['formType']) ? $actions['actions'][$type]['formType'] : 'genericstage_settings'; $formTypeOptions = !empty($actions['actions'][$type]['formTypeOptions']) ? $actions['actions'][$type]['formTypeOptions'] : array(); $form = $this->get('form.factory')->create('stageaction', array(), array('formType' => $formType, 'formTypeOptions' => $formTypeOptions)); $html = $this->renderView('MauticStageBundle:Stage:actionform.html.php', array('form' => $this->setFormTheme($form, 'MauticStageBundle:Stage:actionform.html.php', $themes))); $html = str_replace('stageaction', 'stage', $html); $dataArray['html'] = $html; $dataArray['success'] = 1; } } return $this->sendJsonResponse($dataArray); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { foreach ($options['integration_fields'] as $field => $details) { $label = is_array($details) ? $details['label'] : $details; $field = InputHelper::alphanum($field, false, '_'); $builder->add($field, 'choice', array('choices' => $options['lead_fields'], 'label' => $label, 'required' => is_array($details) && isset($details['required']) ? $details['required'] : false, 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'data-placeholder' => ' '))); } }
/** * Obtains a list of available widget types. * * @param string $type of the widget * * @return \Symfony\Component\HttpFoundation\Response */ public function getDataAction($type) { $start = microtime(true); $timezone = InputHelper::clean($this->request->get('timezone', null)); $from = InputHelper::clean($this->request->get('dateFrom', null)); $to = InputHelper::clean($this->request->get('dateTo', null)); $dataFormat = InputHelper::clean($this->request->get('dataFormat', null)); $response = ['success' => 0]; if ($timezone) { $fromDate = new \DateTime($from, new \DateTimeZone($timezone)); $toDate = new \DateTime($to, new \DateTimeZone($timezone)); } else { $fromDate = new \DateTime($from); $toDate = new \DateTime($to); } $params = ['timeUnit' => InputHelper::clean($this->request->get('timeUnit', 'Y')), 'dateFormat' => InputHelper::clean($this->request->get('dateFormat', null)), 'dateFrom' => $fromDate, 'dateTo' => $toDate, 'limit' => InputHelper::int($this->request->get('limit', null)), 'filter' => $this->request->get('filter', [])]; $cacheTimeout = InputHelper::int($this->request->get('cacheTimeout', null)); $widgetHeight = InputHelper::int($this->request->get('height', 300)); $widget = new Widget(); $widget->setParams($params); $widget->setType($type); $widget->setHeight($widgetHeight); if ($cacheTimeout === null) { $widget->setCacheTimeout($cacheTimeout); } $this->model->populateWidgetContent($widget); $data = $widget->getTemplateData(); if (!$data) { return $this->notFound(); } if ($dataFormat == 'raw') { if (isset($data['chartData']['labels']) && isset($data['chartData']['datasets'])) { $rawData = []; foreach ($data['chartData']['datasets'] as $dataset) { $rawData[$dataset['label']] = []; foreach ($dataset['data'] as $key => $value) { $rawData[$dataset['label']][$data['chartData']['labels'][$key]] = $value; } } $data = $rawData; } elseif (isset($data['raw'])) { $data = $data['raw']; } } else { if (isset($data['raw'])) { unset($data['raw']); } } $response['cached'] = $widget->isCached(); $response['execution_time'] = microtime(true) - $start; $response['success'] = 1; $response['data'] = $data; $view = $this->view($response, Codes::HTTP_OK); return $this->handleView($view); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function categoryListAction(Request $request) { $bundle = InputHelper::clean($request->query->get('bundle')); $filter = InputHelper::clean($request->query->get('filter')); $results = $this->factory->getModel('category')->getLookupResults($bundle, $filter, 10); $dataArray = array(); foreach ($results as $r) { $dataArray[] = array("label" => $r['title'] . " ({$r['id']})", "value" => $r['id']); } return $this->sendJsonResponse($dataArray); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function updateSubmissionChartAction(Request $request) { $formId = InputHelper::int($request->request->get('formId')); $amount = InputHelper::int($request->request->get('amount')); $unit = InputHelper::clean($request->request->get('unit')); $dataArray = array('success' => 0); // Download stats per time period $dataArray['stats'] = $this->factory->getEntityManager()->getRepository('MauticFormBundle:Submission')->getSubmissionsSince($formId, $amount, $unit); $dataArray['success'] = 1; return $this->sendJsonResponse($dataArray); }
/** * Format a string * * @param $val * @param $type */ public function _($val, $type, $textOnly = false, $round = 1) { if (empty($val)) { return $val; } switch ($type) { case 'array': if (!is_array($val)) { //assume that it's serialized $unserialized = unserialize($val); if ($unserialized) { $val = $unserialized; } } $stringParts = array(); foreach ($val as $k => $v) { if (is_array($v)) { $stringParts = $this->_($v, 'array', $textOnly, $round + 1); } else { $stringParts[] = $v; } } if ($round === 1) { $string = implode('; ', $stringParts); } else { $string = implode(', ', $stringParts); } break; case 'datetime': $string = $this->dateHelper->toFull($val, 'utc'); break; case 'time': $string = $this->dateHelper->toTime($val, 'utc'); break; case 'date': $string = $this->dateHelper->toDate($val, 'utc'); break; case 'url': $string = $textOnly ? $val : '<a href="' . $val . '" target="_new">' . $val . '</a>'; break; case 'email': $string = $textOnly ? $val : '<a href="mailto:' . $val . '">' . $val . '</a>'; break; case 'int': $string = (int) $val; break; default: $string = InputHelper::clean($val); break; } return $string; }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function updateConnectionsAction(Request $request) { $session = $this->factory->getSession(); $campaignId = InputHelper::clean($request->query->get('campaignId')); $canvasSettings = $this->request->request->get('canvasSettings', array(), true); if (empty($campaignId)) { $dataArray = array('success' => 0); } else { $session->set('mautic.campaign.' . $campaignId . '.events.canvassettings', $canvasSettings); $dataArray = array('success' => 1); } return $this->sendJsonResponse($dataArray); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function updateGraphAction(Request $request) { $reportId = InputHelper::int($request->request->get('reportId')); $options = InputHelper::clean($request->request->all()); $dataArray = array('success' => 0); /* @type \Mautic\ReportBundle\Model\ReportModel $model */ $model = $this->factory->getModel('report'); $report = $model->getEntity($reportId); $options['ignoreTableData'] = true; $reportData = $model->getReportData($report, $this->container->get('form.factory'), $options); $dataArray['graph'] = $reportData['graphs'][$options['graphName']]['data']; $dataArray['success'] = 1; return $this->sendJsonResponse($dataArray); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function generatePreviewAction(Request $request) { $data = ['html' => '', 'style' => '']; $focus = $request->request->all(); if (isset($focus['focus'])) { $focusArray = InputHelper::_($focus['focus']); if (!empty($focusArray['style']) && !empty($focusArray['type'])) { /** @var \MauticPlugin\MauticFocusBundle\Model\FocusModel $model */ $model = $this->getModel('focus'); $focusArray['id'] = 'preview'; $data = $model->generateJavascript($focusArray, true); } } return $this->sendJsonResponse($data); }
public function onKernelRequest(GetResponseEvent $event) { if ($event->isMasterRequest()) { // get the current event request $request = $event->getRequest(); $requestUri = $request->getRequestUri(); $formGenerateUrl = $this->router->generate('mautic_form_generateform'); if (strpos($requestUri, $formGenerateUrl) !== false) { $id = InputHelper::_($this->request->get('id')); if (strpos($id, 'mf-') === 0) { $mfId = str_replace('mf-', '', $id); $focusGenerateUrl = $this->router->generate('mautic_focus_generate', ['id' => $mfId]); $event->setResponse(new RedirectResponse($focusGenerateUrl)); } } } }
/** * Delete a file from /media directory * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function deleteAction() { $src = InputHelper::clean($this->request->request->get('src')); $response = array('deleted' => false); $imagePath = $this->getMediaAbsolutePath() . '/' . basename($src); if (!file_exists($imagePath)) { $this->response['error'] = 'File does not exist'; $this->statusCode = Response::HTTP_INTERNAL_SERVER_ERROR; } elseif (!is_writable($imagePath)) { $this->response['error'] = 'File is not writable'; $this->statusCode = Response::HTTP_INTERNAL_SERVER_ERROR; } else { unlink($imagePath); $this->response['deleted'] = true; } return $this->sendJsonResponse($this->response, $this->statusCode); }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function getNetworkFormAction(Request $request) { // get the form type $type = InputHelper::clean($request->request->get('networkType')); // default to empty $dataArray = ['html' => '', 'success' => 0]; if (!empty($type)) { //get the HTML for the form // get the network type form $form = $this->get('form.factory')->create($type, [], ['label' => false, 'csrf_protection' => false]); $html = $this->renderView('MauticSocialBundle:FormTheme:' . $type . '_widget.html.php', ['form' => $form->createView()]); $html = str_replace([$type . '[', $type . '_', $type], ['monitoring[properties][', 'monitoring_properties_', 'monitoring'], $html); $dataArray['html'] = $html; $dataArray['success'] = 1; } return $this->sendJsonResponse($dataArray); }
/** * @param $formId * @param $label */ public function generateAlias($label, &$aliases) { // Some labels are quite long if a question so cut this short $alias = substr(strtolower(InputHelper::alphanum($label, false, '_')), 0, 25); if (substr($alias, -1) == '_') { $alias = substr($alias, 0, -1); } //make sure alias is not already taken $testAlias = $alias; $count = (int) in_array($alias, $aliases); $aliasTag = $count; while ($count) { $testAlias = $alias . $aliasTag; $count = (int) in_array($testAlias, $aliases); $aliasTag++; } $aliases[] = $testAlias; return $testAlias; }
public function indexAction(Request $request, $leadId, $page = 1) { if (empty($leadId)) { return $this->accessDenied(); } $lead = $this->checkLeadAccess($leadId, 'view'); if ($lead instanceof Response) { return $lead; } $this->setListFilters(); $session = $this->get('session'); if ($request->getMethod() == 'POST' && $request->request->has('search')) { $filters = ['search' => InputHelper::clean($request->request->get('search')), 'includeEvents' => InputHelper::clean($request->request->get('includeEvents', [])), 'excludeEvents' => InputHelper::clean($request->request->get('excludeEvents', []))]; $session->set('mautic.lead.' . $leadId . '.timeline.filters', $filters); } else { $filters = null; } $order = [$session->get('mautic.lead.' . $leadId . '.timeline.orderby'), $session->get('mautic.lead.' . $leadId . '.timeline.orderbydir')]; $events = $this->getEngagements($lead, $filters, $order, $page); return $this->delegateView(['viewParameters' => ['lead' => $lead, 'page' => $page, 'events' => $events], 'passthroughVars' => ['route' => false, 'mauticContent' => 'leadTimeline', 'timelineCount' => $events['total']], 'contentTemplate' => 'MauticLeadBundle:Timeline:list.html.php']); }
/** * Generate's default list view. * * @param $leadId * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function indexAction($leadId = 0, $page = 1) { if (empty($leadId)) { return $this->accessDenied(); } $lead = $this->checkLeadAccess($leadId, 'view'); if ($lead instanceof Response) { return $lead; } if ($this->request->getMethod() == 'POST') { $this->setListFilters(); } $session = $this->get('session'); //set limits $limit = $session->get('mautic.lead.' . $lead->getId() . '.note.limit', $this->get('mautic.helper.core_parameters')->getParameter('default_pagelimit')); $start = $page === 1 ? 0 : ($page - 1) * $limit; if ($start < 0) { $start = 0; } $search = $this->request->get('search', $session->get('mautic.lead.' . $lead->getId() . '.note.filter', '')); $session->set('mautic.lead.' . $lead->getId() . '.note.filter', $search); //do some default filtering $orderBy = $session->get('mautic.lead.' . $lead->getId() . '.note.orderby', 'n.dateTime'); $orderByDir = $session->get('mautic.lead.' . $lead->getId() . '.note.orderbydir', 'DESC'); $model = $this->getModel('lead.note'); $force = [['column' => 'n.lead', 'expr' => 'eq', 'value' => $lead]]; $tmpl = $this->request->isXmlHttpRequest() ? $this->request->get('tmpl', 'index') : 'index'; $noteType = InputHelper::clean($this->request->request->get('noteTypes', [], true)); if (empty($noteType) && $tmpl == 'index') { $noteType = $session->get('mautic.lead.' . $lead->getId() . '.notetype.filter', []); } $session->set('mautic.lead.' . $lead->getId() . '.notetype.filter', $noteType); $noteTypes = ['general' => 'mautic.lead.note.type.general', 'email' => 'mautic.lead.note.type.email', 'call' => 'mautic.lead.note.type.call', 'meeting' => 'mautic.lead.note.type.meeting']; if (!empty($noteType)) { $force[] = ['column' => 'n.type', 'expr' => 'in', 'value' => $noteType]; } $items = $model->getEntities(['filter' => ['force' => $force, 'string' => $search], 'start' => $start, 'limit' => $limit, 'orderBy' => $orderBy, 'orderByDir' => $orderByDir, 'hydration_mode' => 'HYDRATE_ARRAY']); $security = $this->get('mautic.security'); return $this->delegateView(['viewParameters' => ['notes' => $items, 'lead' => $lead, 'page' => $page, 'limit' => $limit, 'search' => $search, 'noteType' => $noteType, 'noteTypes' => $noteTypes, 'tmpl' => $tmpl, 'permissions' => ['edit' => $security->hasEntityAccess('lead:leads:editown', 'lead:leads:editother', $lead->getPermissionUser()), 'delete' => $security->hasEntityAccess('lead:leads:deleteown', 'lead:leads:deleteown', $lead->getPermissionUser())]], 'passthroughVars' => ['route' => false, 'mauticContent' => 'leadNote', 'noteCount' => count($items)], 'contentTemplate' => 'MauticLeadBundle:Note:list.html.php']); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function fetchRemoteFilesAction(Request $request) { $provider = InputHelper::string($request->request->get('provider')); $path = InputHelper::string($request->request->get('path', '')); $dispatcher = $this->factory->getDispatcher(); $name = AssetEvents::ASSET_ON_REMOTE_BROWSE; if (!$dispatcher->hasListeners($name)) { return $this->sendJsonResponse(array('success' => 0)); } /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ $integrationHelper = $this->factory->getHelper('integration'); /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integration */ $integration = $integrationHelper->getIntegrationObject($provider); $event = new RemoteAssetBrowseEvent($integration); $dispatcher->dispatch($name, $event); if (!($adapter = $event->getAdapter())) { return $this->sendJsonResponse(array('success' => 0)); } $connector = new Filesystem($adapter); $output = $this->renderView('MauticAssetBundle:Remote:list.html.php', array('connector' => $connector, 'integration' => $integration, 'items' => $connector->listKeys($path))); return $this->sendJsonResponse(array('success' => 1, 'output' => $output)); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function updateFormFieldsAction(Request $request) { $formId = InputHelper::int($request->request->get('formId')); $dataArray = array('success' => 0); $model = $this->factory->getModel('form'); $entity = $model->getEntity($formId); $formFields = $entity->getFields(); $fields = array(); foreach ($formFields as $field) { if ($field->getType() != 'button') { $properties = $field->getProperties(); $options = array(); if (!empty($properties['list']['list'])) { $options = $properties['list']['list']; } $fields[] = array('id' => $field->getId(), 'label' => $field->getLabel(), 'alias' => $field->getAlias(), 'type' => $field->getType(), 'options' => $options); } } $dataArray['fields'] = $fields; $dataArray['success'] = 1; return $this->sendJsonResponse($dataArray); }
/** * @param Request $request * * @return JsonResponse */ protected function getLookupChoiceListAction(Request $request) { $dataArray = []; $modelName = InputHelper::clean($request->query->get('searchKey')); $search = InputHelper::clean($request->query->get(str_replace('.', '_', $modelName))); if (!empty($modelName) && !empty($search)) { /** @var ModelFactory $modelFactory */ $modelFactory = $this->get('mautic.model.factory'); if ($modelFactory->hasModel($modelName)) { $model = $modelFactory->getModel($modelName); if ($model instanceof AjaxLookupModelInterface) { $results = $model->getLookupResults($modelName, $search); foreach ($results as $result) { if (isset($result['label'])) { $result['text'] = $result['label']; } $dataArray[] = $result; } } } } return new JsonResponse($dataArray); }