/** * {@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); }
/** * {@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); }
/** * {@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 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' => ' '))); } }
/** * @param $entity * @param $unlock * @return mixed */ public function saveEntity($entity, $unlock = true) { if (!$entity instanceof LeadField) { throw new MethodNotAllowedHttpException(array('LeadEntity')); } $isNew = $entity->getId() ? false : true; //set some defaults $this->setTimestamps($entity, $isNew, $unlock); $alias = $entity->getAlias(); if ($isNew) { if (empty($alias)) { $alias = strtolower(InputHelper::alphanum($entity->getName())); } // clean the alias $alias = $this->cleanAlias($alias); // make sure alias is not already taken $repo = $this->getRepository(); $testAlias = $alias; $aliases = $repo->getAliases($entity->getId()); $count = (int) in_array($testAlias, $aliases); $aliasTag = $count; while ($count) { $testAlias = $alias . $aliasTag; $count = (int) in_array($testAlias, $aliases); $aliasTag++; } if ($testAlias != $alias) { $alias = $testAlias; } $entity->setAlias($alias); } if ($entity->getType() == 'time') { //time does not work well with list filters $entity->setIsListable(false); } $event = $this->dispatchEvent("pre_save", $entity, $isNew); $this->getRepository()->saveEntity($entity); $this->dispatchEvent("post_save", $entity, $isNew, $event); if ($entity->getId()) { //create the field as its own column in the leads table $leadsSchema = $this->factory->getSchemaHelper('column', 'leads'); if ($isNew || !$isNew && !$leadsSchema->checkColumnExists($alias)) { $leadsSchema->addColumn(array('name' => $alias, 'type' => 'text', 'options' => array('notnull' => false))); $leadsSchema->executeChanges(); } } //update order of other fields $this->reorderFieldsByEntity($entity); }
/** * @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; }
/** * Generate a form name for HTML attributes */ public function generateFormName() { $name = strtolower(InputHelper::alphanum(InputHelper::transliterate($this->name))); return empty($name) ? 'form-' . $this->id : $name; }
/** * {@inheritdoc} * * @param Page $entity * @param bool $unlock */ 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); } $now = new \DateTime(); //set the author for new pages if (!$entity->isNew()) { //increase the revision $revision = $entity->getRevision(); $revision++; $entity->setRevision($revision); //reset the variant hit and start date if there are any changes $changes = $entity->getChanges(); $isVariant = $entity->getVariantStartDate(); if ($isVariant !== null && !empty($changes) && empty($this->inConversion)) { $entity->setVariantHits(0); $entity->setVariantStartDate($now); } } parent::saveEntity($entity, $unlock); //also reset variants if applicable due to changes if (!empty($changes) && empty($this->inConversion)) { $parent = $entity->getVariantParent(); $children = !empty($parent) ? $parent->getVariantChildren() : $entity->getVariantChildren(); $variants = array(); if (!empty($parent)) { $parent->setVariantHits(0); $parent->setVariantStartDate($now); $variants[] = $parent; } if (count($children)) { foreach ($children as $child) { $child->setVariantHits(0); $child->setVariantStartDate($now); $variants[] = $child; } } //if the parent was changed, then that parent/children must also be reset if (isset($changes['variantParent'])) { $parent = $this->getEntity($changes['variantParent'][0]); if (!empty($parent)) { $parent->setVariantHits(0); $parent->setVariantStartDate($now); $variants[] = $parent; $children = $parent->getVariantChildren(); if (count($children)) { foreach ($children as $child) { $child->setVariantHits(0); $child->setVariantStartDate($now); $variants[] = $child; } } } } if (!empty($variants)) { $this->saveEntities($variants, false); } } }
/** * @param $entity * @param $unlock * @return mixed */ public function saveEntity($entity, $unlock = true) { if (!$entity instanceof LeadField) { throw new MethodNotAllowedHttpException(array('LeadEntity')); } $isNew = $entity->getId() ? false : true; //set some defaults $this->setTimestamps($entity, $isNew, $unlock); $alias = $entity->getAlias(); if ($isNew) { if (empty($alias)) { $alias = strtolower(InputHelper::alphanum($entity->getName())); } // clean the alias $alias = $this->cleanAlias($alias); // make sure alias is not already taken $repo = $this->getRepository(); $testAlias = $alias; $aliases = $repo->getAliases($entity->getId()); $count = (int) in_array($testAlias, $aliases); $aliasTag = $count; while ($count) { $testAlias = $alias . $aliasTag; $count = (int) in_array($testAlias, $aliases); $aliasTag++; } if ($testAlias != $alias) { $alias = $testAlias; } $entity->setAlias($alias); } $type = $entity->getType(); if ($type == 'time') { //time does not work well with list filters $entity->setIsListable(false); } elseif ($type == 'select' || $type == 'lookup') { // Convert to a string $properties = $entity->getProperties(); if (isset($properties['list']) && is_array($properties['list'])) { $properties['list'] = implode('|', array_map('trim', $properties['list'])); } $entity->setProperties($properties); } $event = $this->dispatchEvent("pre_save", $entity, $isNew); $this->getRepository()->saveEntity($entity); $this->dispatchEvent("post_save", $entity, $isNew, $event); $isUnique = $entity->getIsUniqueIdentifier(); if ($entity->getId()) { //create the field as its own column in the leads table $leadsSchema = $this->factory->getSchemaHelper('column', 'leads'); if ($isNew || !$isNew && !$leadsSchema->checkColumnExists($alias)) { $leadsSchema->addColumn(array('name' => $alias, 'type' => in_array($alias, array('country', 'email')) || $isUnique ? 'string' : 'text', 'options' => array('notnull' => false))); $leadsSchema->executeChanges(); if ($isUnique) { // Get list of current uniques $uniqueIdentifierFields = $this->getUniqueIdentifierFields(); // Always use email $indexColumns = array('email'); $indexColumns = array_merge($indexColumns, array_keys($uniqueIdentifierFields)); $indexColumns[] = $alias; // Only use three to prevent max key length errors $indexColumns = array_slice($indexColumns, 0, 3); try { // Update the unique_identifier_search index /** @var \Mautic\CoreBundle\Doctrine\Helper\IndexSchemaHelper $modifySchema */ $modifySchema = $this->factory->getSchemaHelper('index', 'leads'); $modifySchema->allowColumn($alias); $modifySchema->addIndex($indexColumns, 'unique_identifier_search'); $modifySchema->addIndex(array($alias), 'lead_field' . $alias . '_search'); $modifySchema->executeChanges(); } catch (\Exception $e) { error_log($e); die(var_dump($e)); } } } } //update order of other fields $this->reorderFieldsByEntity($entity); }
/** * Export report * * @param $format * @param $report * @param $reportData * * @return StreamedResponse|Response * @throws \Exception */ public function exportResults($format, $report, $reportData) { $formatter = $this->formatterHelper; $date = (new DateTimeHelper())->toLocalString(); $name = str_replace(' ', '_', $date) . '_' . InputHelper::alphanum($report->getName(), false, '-'); switch ($format) { case 'csv': $response = new StreamedResponse(function () use($reportData, $report, $formatter) { $handle = fopen('php://output', 'r+'); $header = []; //build the data rows foreach ($reportData['data'] as $count => $data) { $row = []; foreach ($data as $k => $v) { if ($count === 0) { //set the header $header[] = $k; } $row[] = $formatter->_($v, $reportData['columns'][$reportData['dataColumns'][$k]]['type'], true); } if ($count === 0) { //write the row fputcsv($handle, $header); } else { fputcsv($handle, $row); } //free memory unset($row, $reportData['data'][$count]); } fclose($handle); }); $response->headers->set('Content-Type', 'application/force-download'); $response->headers->set('Content-Type', 'application/octet-stream'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $name . '.csv"'); $response->headers->set('Expires', 0); $response->headers->set('Cache-Control', 'must-revalidate'); $response->headers->set('Pragma', 'public'); return $response; case 'html': $content = $this->templatingHelper->getTemplating()->renderResponse('MauticReportBundle:Report:export.html.php', ['data' => $reportData['data'], 'columns' => $reportData['columns'], 'pageTitle' => $name, 'graphs' => $reportData['graphs'], 'report' => $report, 'dateFrom' => $reportData['dateFrom'], 'dateTo' => $reportData['dateTo']])->getContent(); return new Response($content); case 'xlsx': if (class_exists('PHPExcel')) { $response = new StreamedResponse(function () use($formatter, $reportData, $report, $name) { $objPHPExcel = new \PHPExcel(); $objPHPExcel->getProperties()->setTitle($name); $objPHPExcel->createSheet(); $header = []; //build the data rows foreach ($reportData['data'] as $count => $data) { $row = []; foreach ($data as $k => $v) { if ($count === 0) { //set the header $header[] = $k; } $row[] = $formatter->_($v, $reportData['columns'][$reportData['dataColumns'][$k]]['type'], true); } //write the row if ($count === 0) { $objPHPExcel->getActiveSheet()->fromArray($header, null, 'A1'); } else { $rowCount = $count + 1; $objPHPExcel->getActiveSheet()->fromArray($row, null, "A{$rowCount}"); } //free memory unset($row, $reportData['data'][$count]); } $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->setPreCalculateFormulas(false); $objWriter->save('php://output'); }); $response->headers->set('Content-Type', 'application/force-download'); $response->headers->set('Content-Type', 'application/octet-stream'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $name . '.xlsx"'); $response->headers->set('Expires', 0); $response->headers->set('Cache-Control', 'must-revalidate'); $response->headers->set('Pragma', 'public'); return $response; } throw new \Exception('PHPExcel is required to export to Excel spreadsheets'); default: return new Response(); } }
private function getDirectoryName($newName) { return InputHelper::alphanum($newName, true); }
$wrapDiv = false; } $count = 0; $firstId = 'mauticform_' . $containerType . '_' . $type . '_' . $field['alias'] . '_' . \Mautic\CoreBundle\Helper\InputHelper::alphanum($list[0]); $formButtons = !empty($inForm) ? $view->render('MauticFormBundle:Builder:actions.html.php', array('deleted' => !empty($deleted) ? $deleted : false, 'id' => $id, 'formId' => $formId, 'formName' => $formName)) : ''; $label = !$field['showLabel'] ? '' : <<<HTML <label {$labelAttr} for="{$firstId}">{$view->escape($field['label'])}</label> HTML; $help = empty($field['helpMessage']) ? '' : <<<HTML <span class="mauticform-helpmessage">{$field['helpMessage']}</span> HTML; $options = array(); foreach ($list as $l) { $id = $field['alias'] . '_' . \Mautic\CoreBundle\Helper\InputHelper::alphanum($l); $checked = $field['defaultValue'] == $l ? 'checked="checked"' : ''; $checkboxBrackets = $type == 'checkbox' ? '[]' : ''; $option = <<<HTML <label id="mauticform_{$containerType}_label_{$id}" for="mauticform_{$containerType}_{$type}_{$id}" {$optionLabelAttr}> <input {$inputAttr}{$checked} name="mauticform[{$field['alias']}]{$checkboxBrackets}" id="mauticform_{$containerType}_{$type}_{$id}" type="{$type}" value="{$view->escape($l)}" /> {$view->escape($l)} </label> HTML; if ($wrapDiv) { $option = <<<HTML <div class="mauticform-{$containerType}-row">{$option} </div> HTML;
<?php /** * @package Mautic * @copyright 2014 Mautic Contributors. All rights reserved. * @author Mautic * @link http://mautic.org * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ $formName = strtolower(\Mautic\CoreBundle\Helper\InputHelper::alphanum($form->getName())); $fields = $form->getFields(); $required = array(); ?> <?php echo $view->render($theme . 'MauticFormBundle:Builder:script.html.php', array('form' => $form, 'formName' => $formName)); ?> <?php echo $view->render($theme . 'MauticFormBundle:Builder:style.html.php', array('form' => $form, 'formName' => $formName)); ?> <div id="mauticform_wrapper_<?php echo $formName; ?> " class="mauticform_wrapper"> <form autocomplete="off" target="mauticiframe_<?php echo $formName; ?> " role="form" method="post" action="<?php echo $view['router']->generate('mautic_form_postresults', array('formId' => $form->getId()), true);
/** * @param array $filters * @param QueryBuilder $queryBuilder * @param array $filterDefinitions * * @return bool */ private function applyFilters(array $filters, QueryBuilder $queryBuilder, array $filterDefinitions) { $expr = $queryBuilder->expr(); $filterExpr = $expr->andX(); if (count($filters)) { foreach ($filters as $filter) { $exprFunction = isset($filter['expr']) ? $filter['expr'] : $filter['condition']; $paramName = InputHelper::alphanum($filter['column']); switch ($exprFunction) { case 'notEmpty': $filterExpr->add($expr->isNotNull($filter['column'])); $filterExpr->add($expr->neq($filter['column'], $expr->literal(''))); break; case 'empty': $filterExpr->add($expr->isNull($filter['column'])); $filterExpr->add($expr->eq($filter['column'], $expr->literal(''))); break; default: if (trim($filter['value']) == '') { // Ignore empty break; } $columnValue = ":{$paramName}"; switch ($filterDefinitions[$filter['column']]['type']) { case 'bool': case 'boolean': if ((int) $filter['value'] > 1) { // Ignore the "reset" value of "2" break; } $queryBuilder->setParameter($paramName, $filter['value'], 'boolean'); break; case 'float': $columnValue = (double) $filter['value']; break; case 'int': case 'integer': $columnValue = (int) $filter['value']; break; default: $queryBuilder->setParameter($paramName, $filter['value']); } $filterExpr->add($expr->{$exprFunction}($filter['column'], $columnValue)); } } } if ($filterExpr->count()) { $queryBuilder->andWhere($filterExpr); return true; } return false; }
/** * Exports the widgets of current user into a json file * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function exportAction() { /** @var \Mautic\DashboardBundle\Model\DashboardModel $model */ $model = $this->factory->getModel('dashboard'); $widgetsPaginator = $model->getWidgets(); $usersName = $this->factory->getUser()->getName(); $dateTime = new \DateTime(); $dateStamp = $dateTime->format('Y-m-d H:i:s'); $name = $this->request->get('name', 'dashboard-of-' . str_replace(' ', '-', $usersName) . '-' . $dateStamp); $description = $this->get('translator')->trans('mautic.dashboard.generated_by', array('%name%' => $usersName, '%date%' => $dateStamp)); $dashboard = array('name' => $name, 'description' => $description, 'widgets' => array()); foreach ($widgetsPaginator as $widget) { $dashboard['widgets'][] = array('name' => $widget->getName(), 'width' => $widget->getWidth(), 'height' => $widget->getHeight(), 'ordering' => $widget->getOrdering(), 'type' => $widget->getType(), 'params' => $widget->getParams(), 'template' => $widget->getTemplate()); } // Make the filename safe $filename = InputHelper::alphanum($name, false, '_') . '.json'; if ($this->request->get('save', false)) { // Save to the user's folder $dir = $this->factory->getSystemPath('dashboard.user'); file_put_contents($dir . '/' . $filename, json_encode($dashboard)); return $this->redirect($this->get('router')->generate('mautic_dashboard_action', array('objectAction' => 'import'))); } $response = new JsonResponse($dashboard); $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT); $response->headers->set('Content-Length', strlen($response->getContent())); $response->headers->set('Content-Type', 'application/force-download'); $response->headers->set('Content-Type', 'application/octet-stream'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); $response->headers->set('Expires', 0); $response->headers->set('Cache-Control', 'must-revalidate'); $response->headers->set('Pragma', 'public'); return $response; }
/** * @param \Doctrine\ORM\QueryBuilder $q * @param array $args */ protected function buildOrderByClause(&$q, array $args) { $orderBy = array_key_exists('orderBy', $args) ? $args['orderBy'] : ''; $orderByDir = InputHelper::alphanum(array_key_exists('orderByDir', $args) ? $args['orderByDir'] : ''); if (empty($orderBy)) { $defaultOrder = $this->getDefaultOrder(); foreach ($defaultOrder as $order) { $q->addOrderBy($order[0], $order[1]); } } else { //add direction after each column $parts = explode(',', $orderBy); foreach ($parts as $order) { $order = InputHelper::alphanum($order, false, false, ['_', '.']); $q->addOrderBy($order, $orderByDir); } } }
/** * @param $entity * @param $unlock * @return mixed */ public function saveEntity($entity, $unlock = true) { if (!$entity instanceof Channel) { throw new MethodNotAllowedHttpException(array('Channel')); } $isNew = $entity->getId() ? false : true; //set some defaults $this->setTimestamps($entity, $isNew, $unlock); $name = $entity->getName(); $name = strtolower(InputHelper::alphanum($name)); //make sure alias is not already taken $repo = $this->getRepository(); $testName = $name; $names = $repo->getNames($entity->getId()); $count = (int) in_array($testName, $names); $nameTag = $count; while ($count) { $testAlias = $testName . $nameTag; $count = (int) in_array($testAlias, $names); $nameTag++; } if ($testName != $name) { $name = $testName; } $entity->setName($name); $event = $this->dispatchEvent("pre_save", $entity, $isNew); $this->getRepository()->saveEntity($entity); $this->dispatchEvent("post_save", $entity, $isNew, $event); }
/** * Cleans a string to be used as an alias. The returned string will be alphanumeric or underscore, less than 25 characters * and if it is a reserved SQL keyword, it will be prefixed with f_ * * @param string $alias * @param string $prefix Used when the alias is a reserved keyword by the database platform * @param int|bool $maxLength Maximum number of characters used; 0 to disable * @param string $spaceCharacter Character to replace spaces with * @return string * @throws \Doctrine\DBAL\DBALException */ public function cleanAlias($alias, $prefix = '', $maxLength = false, $spaceCharacter = '_') { // Transliterate to latin characters $alias = InputHelper::transliterate(trim($alias)); // Some labels are quite long if a question so cut this short $alias = strtolower(InputHelper::alphanum($alias, false, $spaceCharacter)); // Trim if applicable if ($maxLength) { $alias = substr($alias, 0, $maxLength); } if (substr($alias, -1) == '_') { $alias = substr($alias, 0, -1); } // Check that alias is SQL safe since it will be used for the column name $databasePlatform = $this->em->getConnection()->getDatabasePlatform(); $reservedWords = $databasePlatform->getReservedKeywordsList(); if ($reservedWords->isKeyword($alias) || is_numeric($alias)) { $alias = $prefix . $alias; } return $alias; }
$wrapDiv = false; } $count = 0; $firstId = 'mauticform_' . $containerType . '_' . $type . '_' . $field['alias'] . '_' . InputHelper::alphanum(InputHelper::transliterate($list[0])) . '1'; $formButtons = !empty($inForm) ? $view->render('MauticFormBundle:Builder:actions.html.php', ['id' => $id, 'formId' => $formId, 'formName' => $formName]) : ''; $label = !$field['showLabel'] ? '' : <<<HTML <label {$labelAttr} for="{$firstId}">{$view->escape($field['label'])}</label> HTML; $help = empty($field['helpMessage']) ? '' : <<<HTML <span class="mauticform-helpmessage">{$field['helpMessage']}</span> HTML; $options = []; foreach ($list as $counter => $l) { $id = $field['alias'] . '_' . InputHelper::alphanum(InputHelper::transliterate($l)) . $counter; $checked = $field['defaultValue'] == $l ? 'checked="checked"' : ''; $checkboxBrackets = $type == 'checkbox' ? '[]' : ''; $option = <<<HTML <label id="mauticform_{$containerType}_label_{$id}" for="mauticform_{$containerType}_{$type}_{$id}" {$optionLabelAttr}> <input {$inputAttr}{$checked} name="mauticform[{$field['alias']}]{$checkboxBrackets}" id="mauticform_{$containerType}_{$type}_{$id}" type="{$type}" value="{$view->escape($l)}" /> {$view->escape($l)} </label> HTML; if ($wrapDiv) { $option = <<<HTML <div class="mauticform-{$containerType}-row">{$option} </div> HTML;
<?php /** * @copyright 2014 Mautic Contributors. All rights reserved * @author Mautic * * @link http://mautic.org * * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ use Mautic\CoreBundle\Helper\InputHelper; $formName = '_' . strtolower(InputHelper::alphanum(InputHelper::transliterate($form->getName())) . '_focus'); $jsFormName = ltrim($formName, '_'); $fields = $form->getFields(); $required = []; if (empty($preview)) { echo $view->render('MauticFormBundle:Builder:script.html.php', ['form' => $form, 'formName' => $formName]); ?> <script> var MauticFocusHandler = function (messageType, message) { // Store the HTML var wrapper = document.getElementById('mauticform_wrapper<?php echo $formName; ?> '); var innerForm = wrapper.getElementsByClassName('mauticform-innerform'); innerForm[0].style.display = "none"; <?php if ($style == 'page') {
/** * @return array */ public function getAvailableLeadFields($settings = array()) { $zohoFields = array(); $silenceExceptions = isset($settings['silence_exceptions']) ? $settings['silence_exceptions'] : true; try { if ($this->isAuthorized()) { $leadObject = $this->getApiHelper()->getLeadFields(); if ($leadObject == null || isset($leadObject['response']) && isset($leadObject['response']['error'])) { return array(); } $zohoFields = array(); foreach ($leadObject['Leads']['section'] as $optgroup) { //$zohoFields[$optgroup['dv']] = array(); if (!array_key_exists(0, $optgroup['FL'])) { $optgroup['FL'] = array($optgroup['FL']); } foreach ($optgroup['FL'] as $field) { if (!(bool) $field['isreadonly'] || in_array($field['type'], array('Lookup', 'OwnerLookup', 'Boolean'))) { continue; } $key = InputHelper::alphanum($field['dv']); $zohoFields[$key] = array('type' => 'string', 'label' => $field['label'], 'dv' => $field['dv'], 'required' => $field['req'] == 'true'); } } } } catch (ErrorException $exception) { $this->logIntegrationError($exception); if (!$silenceExceptions) { throw $exception; } return false; } return $zohoFields; }
/** * Cleans a string to be used as an alias. The returned string will be alphanumeric or underscore, less than 25 characters * and if it is a reserved SQL keyword, it will be prefixed with f_ * * @param $alias * * @return string * @throws \Doctrine\DBAL\DBALException */ public function cleanAlias($alias) { // Some labels are quite long if a question so cut this short $alias = substr(strtolower(InputHelper::alphanum($alias, false, '_')), 0, 25); if (substr($alias, -1) == '_') { $alias = substr($alias, 0, -1); } // Check that alias is SQL safe since it will be used for the column name $databasePlatform = $this->em->getConnection()->getDatabasePlatform(); $reservedWords = $databasePlatform->getReservedKeywordsList(); if ($reservedWords->isKeyword($alias) || is_numeric($alias)) { $alias = 'f_' . $alias; } return $alias; }
/** * Generate a form name for HTML attributes */ public function generateFormName() { return strtolower(InputHelper::alphanum(InputHelper::transliterate($this->name))); }
/** * Writes in form values from get parameters * * @param $form * @param $formHtml */ public function populateValuesWithGetParameters($form, &$formHtml) { $request = $this->factory->getRequest(); $formName = strtolower(\Mautic\CoreBundle\Helper\InputHelper::alphanum($form->getName())); $fields = $form->getFields(); foreach ($fields as $f) { $alias = $f->getAlias(); if ($request->query->has($alias)) { preg_match('/<input id="mauticform_input_' . $formName . '_' . $alias . '"(.*?)value="(.*?)"(.*?)\\/>/i', $formHtml, $match); if (!empty($match)) { //replace value with GET $replace = '<input id="mauticform_input_' . $formName . '_' . $alias . '"' . $match[1] . 'value="' . urldecode($request->query->get($alias)) . '"' . $match[3] . '/>'; $formHtml = str_replace($match[0], $replace, $formHtml); } } } }
/** * {@inheritdoc} */ public function saveEntity($entity, $unlock = true) { $isNew = $entity->getId() ? false : true; if ($isNew) { $alias = substr(strtolower(InputHelper::alphanum($entity->getName())), 0, 10); $entity->setAlias($alias); } //save the form so that the ID is available for the form html parent::saveEntity($entity, $unlock); //now build the form table if ($entity->getId()) { $this->createTableSchema($entity, $isNew); } $this->generateHtml($entity); }