public function executePostActionsHook($strAction, \DataContainer $dc) { if ($strAction !== static::$uploadAction) { return false; } // Check whether the field is allowed for regular users if (!isset($GLOBALS['TL_DCA'][$dc->table]['fields'][\Input::post('field')]) || $GLOBALS['TL_DCA'][$dc->table]['fields'][\Input::post('field')]['exclude'] && !\BackendUser::getInstance()->hasAccess($dc->table . '::' . \Input::post('field'), 'alexf')) { \System::log('Field "' . \Input::post('field') . '" is not an allowed selector field (possible SQL injection attempt)', __METHOD__, TL_ERROR); $objResponse = new ResponseError(); $objResponse->setMessage('Bad Request'); $objResponse->output(); } $this->name = \Input::post('field'); $this->id = \Input::post('field'); $this->field = \Input::post('field'); if ($dc->activeRecord === null) { $dc->activeRecord = General::getModelInstance($dc->table, $dc->id); } // add dca attributes $this->addAttributes(\Widget::getAttributesFromDca($GLOBALS['TL_DCA'][$dc->table]['fields'][$this->name], $this->name)); $objResponse = $this->upload(); /** @var Response */ if ($objResponse instanceof Response) { $objResponse->output(); } }
protected function layoutRedirect(\DC_Table $dc, $mode = "mootools") { //Variables $activeRecord = $dc->activeRecord; $strTemplates = deserialize($mode == "mootools" ? $activeRecord->mootools : $activeRecord->jquery); $strField = $mode == "mootools" ? $this->mootoolsField : $this->jqueryField; $content = '<div class="clr w50 hauto">'; if (!is_array($strTemplates)) { $strTemplates = array(); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $rawValue = $this->saveData($_POST[$strField] ?: '', $dc, $mode); } else { $field = $mode == "mootools" ? $this->mootoolsField : $this->jqueryField; $rawValue = $activeRecord->{$field}; } $value = $rawValue; $inArray = $mode == "mootools" ? 'moo_redirect' : 'j_redirect'; if (in_array($inArray, $strTemplates)) { $content .= '<h3><label for="ctrl_' . $mode . 'Redirect">Weiterleitung (Redirect) Ziel</label></h3>'; $arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$strField]; $arrData['name'] = $inArray; $arrWidget = \Widget::getAttributesFromDca($arrData, $strField, $value, $strField, $this->strTable); $objWidget = new $GLOBALS['BE_FFL']['pageTree']($arrWidget); $content .= $objWidget->generate(); } return $content . '</div>'; }
public function executePostActionsHook($strAction, \DataContainer $dc) { if ($strAction == FieldPalette::$strFieldpaletteRefreshAction) { if (\Input::post('field')) { \Controller::loadDataContainer($dc->table); $strName = \Input::post('field'); $arrField = $GLOBALS['TL_DCA'][$dc->table]['fields'][$strName]; // Die if the field does not exist if (!is_array($arrField)) { header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } /** @var \Widget $strClass */ $strClass = $GLOBALS['BE_FFL'][$arrField['inputType']]; // Die if the class is not defined or inputType is not fieldpalette if ($arrField['inputType'] != 'fieldpalette' || !class_exists($strClass)) { header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } $arrData = \Widget::getAttributesFromDca($arrField, $strName, $dc->activeRecord->{$strName}, $strName, $dc->table, $dc); /** @var \Widget $objWidget */ $objWidget = new $strClass($arrData); $objWidget->currentRecord = $dc->id; die(json_encode(array('field' => $strName, 'target' => '#ctrl_' . $strName, 'content' => $objWidget->generate()))); } header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } }
/** * Get an instance of \Widget by passing fieldname and dca data * @param $strField string The field name * @param $arrDca array The DCA * @param null $varValue array * @param string $strDbField string The database field name * @param string $strTable The table * @param null $objDca object The data container * * @return bool */ public static function getFrontendFormField($strField, array $arrDca, $varValue = null, $strDbField = '', $strTable = '', $objDca = null) { if (!($strClass = $GLOBALS['TL_FFL'][$arrDca['inputType']])) { return false; } return new $strClass(\Widget::getAttributesFromDca($arrDca, $strField, $varValue, $strDbField, $strTable, $objDca)); }
protected function compile() { $this->Template->formId = $this->strFormId; $arrFieldDcas = array('email' => array('label' => &$GLOBALS['TL_LANG']['tl_module']['email'], 'inputType' => 'text', 'eval' => array('rgxp' => 'email', 'mandatory' => true)), 'submit' => array('inputType' => 'submit', 'label' => &$GLOBALS['TL_LANG']['MSC']['cancel'])); $arrWidgets = array(); foreach ($arrFieldDcas as $strName => $arrData) { if ($strClass = $GLOBALS['TL_FFL'][$arrData['inputType']]) { $arrWidgets[] = new $strClass(\Widget::getAttributesFromDca($arrData, $strName)); } } if (\Input::post('FORM_SUBMIT') == $this->strFormId) { // validate foreach ($arrWidgets as $objWidget) { $objWidget->validate(); if ($objWidget->hasErrors()) { $this->blnDoNotSubmit = true; } } if (!$this->blnDoNotSubmit) { // cancel subscription $strEmail = \Input::post('email'); $arrArchives = deserialize($this->iso_cancellationArchives, true); $blnNoSuccess = false; foreach ($arrArchives as $intArchive) { if (($objSubscription = Subscription::findBy(array('email=?', 'pid=?'), array($strEmail, $intArchive))) === null) { if (count($arrArchives) == 1) { $this->Template->error = sprintf($GLOBALS['TL_LANG']['MSC']['iso_subscriptionDoesNotExist'], $strEmail, SubscriptionArchive::findByPk($intArchive)->title); $blnNoSuccess = true; } break; } $objSubscription->delete(); } if (!$blnNoSuccess) { // success message if (count($arrArchives) > 1) { $this->Template->success = $GLOBALS['TL_LANG']['MSC']['iso_subscriptionsCancelledSuccessfully']; } else { $this->Template->success = sprintf($GLOBALS['TL_LANG']['MSC']['iso_subscriptionCancelledSuccessfully'], $strEmail, SubscriptionArchive::findByPk($arrArchives[0])->title); } // redirect if ($this->jumpTo && ($objPageRedirect = \PageModel::findByPk($this->jumpTo)) !== null) { \Controller::redirect(\Controller::generateFrontendUrl($objPageRedirect->row())); } } } } // parse (validated) widgets $this->Template->fields = implode('', array_map(function ($objWidget) { return $objWidget->parse(); }, $arrWidgets)); }
public function compile() { \System::loadLanguageFile('tl_iso_gallery'); $strBuffer = ' <table style="width:100%"> <thead> <tr> <th>' . $GLOBALS['TL_LANG']['tl_iso_gallery']['name'][0] . '</th> <th>' . $GLOBALS['TL_LANG']['tl_iso_gallery']['lightbox_template'][0] . '<span class="mandatory">*</span></th> </tr> </thead> <tbody>'; foreach ($this->objGaleries as $objGallery) { $objSelect = new \SelectMenu(\Widget::getAttributesFromDca(array('options' => array_merge(\Controller::getTemplateGroup('moo_'), \Controller::getTemplateGroup('j_')), 'eval' => array('includeBlankOption' => true, 'mandatory' => true)), 'gallery[' . $objGallery->id . ']')); if (\Input::post('FORM_SUBMIT') == 'tl_iso_upgrade_20010000') { $objSelect->validate(); if (!$objSelect->hasErrors()) { $objGallery->lightbox_template = serialize(array($objSelect->value)); $objGallery->save(); } } $strBuffer .= ' <tr> <td>' . $objGallery->name . '</td> <td>' . $objSelect->generateWithError() . '</td> </tr>'; } $strBuffer .= ' </tbody> </table>'; $this->Template->formSubmit = 'tl_iso_upgrade_20010000'; $this->Template->fields = $strBuffer; $this->Template->matter = $GLOBALS['TL_LANG']['UPG']['20010000']; if (\Input::post('FORM_SUBMIT') == 'tl_iso_upgrade_20010000') { \Controller::reload(); } }
/** * Gets the used and available options for given attribute * * @param string $attribute The attribute name * @param string $label Set to the label of the attribute * * @return array */ protected function getOptionsForAttribute($attribute, &$label) { $usedValues = $this->getUsedValuesForAttribute($attribute, $this->findCategories(), $this->iso_newFilter, $this->iso_list_where); if (empty($usedValues)) { return array(); } // Use the default routine to initialize options data $arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$attribute], $attribute); $label = $arrWidget['label']; $options = $arrWidget['options']; if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$attribute]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) { $options = $objAttribute->getOptionsForProductFilter($usedValues); } elseif (is_array($options)) { $options = array_filter($options, function ($option) use($usedValues) { return in_array($option['value'], $usedValues); }); } else { $options = array(); } return $options; }
/** * Set the submission from request, required to check values before widget validation */ protected function setSubmission() { foreach ($this->dca['fields'] as $strName => $arrField) { $arrData = $this->dca['fields'][$strName]; // unset options_callback, as long as we have no valid backend user unset($arrData['options_callback'], $arrData['options_callback']); $arrAttribues = \Widget::getAttributesFromDca($arrData, $strName, $this->objActiveRecord->{$strName}, $strName, $this->strTable, $this); switch ($this->strMethod) { case FORMHYBRID_METHOD_GET: $this->arrSubmission[$strName] = FormHelper::getGet($strName); break; case FORMHYBRID_METHOD_POST: $this->arrSubmission[$strName] = FormHelper::getPost($strName, $arrAttribues['decodeEntities'], $arrAttribues['allowHtml'], $arrAttribues['preserveTags']); break; } } }
/** * Convert a DCA file configuration to be used with widgets * * @param array $arrData The field configuration array * @param string $strName The field name in the form * @param mixed $varValue The field value * @param string $strField The field name in the database * @param string $strTable The table name * * @return array An array that can be passed to a widget * * @deprecated Use Widget::getAttributesFromDca() instead */ protected function prepareForWidget($arrData, $strName, $varValue = null, $strField = '', $strTable = '') { return \Widget::getAttributesFromDca($arrData, $strName, $varValue, $strField, $strTable); }
/** * Handle the widget preparation. * * @param GetAttributesFromDcaEvent $event The event. * * @return void */ public function handleGetAttributesFromDca(GetAttributesFromDcaEvent $event) { $event->setResult(\Widget::getAttributesFromDca($event->getFieldConfiguration(), $event->getWidgetName(), $event->getValue(), $event->getWidgetId(), $event->getTable(), $event->getDataContainer())); }
/** * Generate a filter form */ protected function generateFilters() { $this->Template->hasFilters = false; if (is_array($this->iso_filterFields) && count($this->iso_filterFields)) { $time = time(); $arrFilters = array(); $arrInput = \Input::post('filter'); $arrCategories = $this->findCategories(); foreach ($this->iso_filterFields as $strField) { $arrValues = array(); $objValues = \Database::getInstance()->execute("\n SELECT DISTINCT p1.{$strField} FROM tl_iso_product p1\n LEFT OUTER JOIN tl_iso_product p2 ON p1.pid=p2.id\n WHERE\n p1.language=''\n " . (BE_USER_LOGGED_IN === true ? '' : "AND p1.published='1' AND (p1.start='' OR p1.start<{$time}) AND (p1.stop='' OR p1.stop>{$time}) ") . "\n AND (\n p1.id IN (\n SELECT pid FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")\n )\n OR p1.pid IN (\n SELECT pid FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")\n )\n )\n " . (BE_USER_LOGGED_IN === true ? '' : " AND (p1.pid=0 OR (p2.published='1' AND (p2.start='' OR p2.start<{$time}) AND (p2.stop='' OR p2.stop>{$time})))") . "\n " . ($this->iso_list_where == '' ? '' : " AND " . Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where))); while ($objValues->next()) { $arrValues[] = deserialize($objValues->{$strField}, false); } if ($this->blnUpdateCache && in_array($arrInput[$strField], $arrValues)) { Isotope::getRequestCache()->setFilterForModule($strField, Filter::attribute($strField)->isEqualTo($arrInput[$strField]), $this->id); } elseif ($this->blnUpdateCache && $arrInput[$strField] == '') { Isotope::getRequestCache()->removeFilterForModule($strField, $this->id); } elseif (($objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id)) !== null && $objFilter->valueNotIn($arrValues)) { // Request cache contains wrong value, delete it! $this->blnUpdateCache = true; Isotope::getRequestCache()->removeFilterForModule($strField, $this->id); RequestCache::deleteById(\Input::get('isorc')); } elseif (!$this->blnUpdateCache) { // Only generate options if we do not reload anyway if (empty($arrValues)) { continue; } $arrData = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField]; if (is_array($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback']) && !empty($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback'])) { foreach ($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrData = $objCallback->{$callback[1]}($strField, $arrData, $this); } } // Use the default routine to initialize options data $arrWidget = \Widget::getAttributesFromDca($arrData, $strField); $objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id); if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strField]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) { $objAttribute->optionsSource = 'attribute'; $arrWidget['options'] = $objAttribute->getOptionsForProductFilter($arrValues); } foreach ($arrValues as $value) { $arrWidget['options'][] = array('value' => $value, 'label' => $value == '' ? ' ' : 'text'); } // Must have options to apply the filter if (!is_array($arrWidget['options'])) { continue; } foreach ($arrWidget['options'] as $k => $option) { if ($option['value'] == '') { $arrWidget['blankOptionLabel'] = $option['label']; unset($arrWidget['options'][$k]); continue; } elseif (!in_array($option['value'], $arrValues) || $option['value'] == '-') { // @deprecated IsotopeAttributeWithOptions::getOptionsForProductFilter already checks this unset($arrWidget['options'][$k]); continue; } $arrWidget['options'][$k]['default'] = null !== $objFilter && $objFilter->valueEquals($option['value']) ? '1' : ''; } // Hide fields with just one option (if enabled) if ($this->iso_filterHideSingle && count($arrWidget['options']) < 2) { continue; } $arrFilters[$strField] = $arrWidget; } } // !HOOK: alter the filters if (isset($GLOBALS['ISO_HOOKS']['generateFilters']) && is_array($GLOBALS['ISO_HOOKS']['generateFilters'])) { foreach ($GLOBALS['ISO_HOOKS']['generateFilters'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrFilters = $objCallback->{$callback}[1]($arrFilters); } } if (!empty($arrFilters)) { $this->Template->hasFilters = true; $this->Template->filterOptions = $arrFilters; } } }
/** * Ajax actions that do require a data container object * @param string * @param \DataContainer */ public function executePostActions($strAction, \DataContainer $dc) { switch ($strAction) { case 'loadTreepicker': $arrData = \Widget::getAttributesFromDca($GLOBALS['TL_DCA'][$dc->table]['fields'][\Input::post('name')], \Input::post('name'), null, \Input::post('name'), $dc->table, $dc); $arrData['id'] = $this->strAjaxName ?: $dc->id; $objWidget = new $GLOBALS['BE_FFL']['treeSelector']($arrData, $dc); echo $objWidget->generateAjax($this->strAjaxId, \Input::post('field'), intval(\Input::post('level'))); exit; break; case 'reloadTreepicker': $intId = \Input::get('id'); $strField = $dc->field = \Input::post('name'); // Handle the keys in "edit multiple" mode if (\Input::get('act') == 'editAll') { $intId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', $strField); $strField = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $strField); } // The field does not exist if (!isset($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField])) { $this->log('Field "' . $strField . '" does not exist in DCA "' . $dc->table . '"', __METHOD__, TL_ERROR); header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } $objRow = null; $varValue = null; // Load the value if ($intId > 0 && $this->Database->tableExists($dc->table)) { $objRow = $this->Database->prepare("SELECT * FROM " . $dc->table . " WHERE id=?")->execute($intId); // The record does not exist if ($objRow->numRows < 1) { $this->log('A record with the ID "' . $intId . '" does not exist in table "' . $dc->table . '"', __METHOD__, TL_ERROR); header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } $varValue = $objRow->{$strField}; $dc->activeRecord = $objRow; } // Call the load_callback if (is_array($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $dc); } elseif (is_callable($callback)) { $varValue = $callback($varValue, $dc); } } } // Set the new value $varValue = \Input::post('value', true); // Convert the selected values if ($varValue != '') { $varValue = trimsplit("\t", $varValue); $varValue = serialize($varValue); } $objWidget = new $GLOBALS['BE_FFL']['treePicker'](\Widget::getAttributesFromDca($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField], $dc->field, $varValue, $strField, $dc->table, $dc)); echo $objWidget->generate(); exit; break; } }
/** * Run the controller and parse the template. * * @return void */ public function run() { $template = new \BackendTemplate('be_picker'); $template->main = ''; // Ajax request. // @codingStandardsIgnoreStart - We need POST access here. if ($_POST && \Environment::get('isAjaxRequest')) { $ajax = new \Ajax(\Input::post('action')); $ajax->executePreActions(); } $strTable = \Input::get('table'); $strField = \Input::get('field'); // Define the current ID. define('CURRENT_ID', $strTable ? \Session::getInstance()->get('CURRENT_ID') : \Input::get('id')); $dispatcher = $GLOBALS['container']['event-dispatcher']; /** @var \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */ $propagator = new EventPropagator($dispatcher); $translator = new TranslatorChain(); $translator->add(new LangArrayTranslator($dispatcher)); $factory = new DcGeneralFactory(); $this->itemContainer = $factory->setContainerName($strTable)->setTranslator($translator)->setEventPropagator($propagator)->createDcGeneral(); $information = (array) $GLOBALS['TL_DCA'][$strTable]['fields'][$strField]; // Merge with the information from the data container. $property = $this->itemContainer->getEnvironment()->getDataDefinition()->getPropertiesDefinition()->getProperty($strField); $extra = $property->getExtra(); $information['eval']['sourceName'] = $extra['sourceName']; $information['eval']['fieldType'] = $extra['fieldType']; /** @var \ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\TreePicker $objTreeSelector */ $objTreeSelector = new $GLOBALS['BE_FFL']['DcGeneralTreePicker'](\Widget::getAttributesFromDca($information, $strField, array_filter(explode(',', \Input::get('value'))), $strField, $strTable, new DcCompat($this->itemContainer->getEnvironment()))); // AJAX request. if (isset($ajax)) { $objTreeSelector->generateAjax(); $ajax->executePostActions(new DcCompat($this->itemContainer->getEnvironment())); } $template->main = $objTreeSelector->generatePopup(); $template->theme = \Backend::getTheme(); $template->base = \Environment::get('base'); $template->language = $GLOBALS['TL_LANGUAGE']; $template->title = specialchars($GLOBALS['TL_LANG']['MSC']['treepicker']); $template->charset = $GLOBALS['TL_CONFIG']['characterSet']; $template->addSearch = $objTreeSelector->searchField; $template->search = $GLOBALS['TL_LANG']['MSC']['search']; $template->action = ampersand(\Environment::get('request')); $template->value = \Session::getInstance()->get($objTreeSelector->getSearchSessionKey()); $template->manager = $GLOBALS['TL_LANG']['MSC']['treepickerManager']; $template->breadcrumb = $GLOBALS['TL_DCA'][$objTreeSelector->foreignTable]['list']['sorting']['breadcrumb']; $template->managerHref = ''; // Add the manager link. if ($objTreeSelector->managerHref) { $template->managerHref = 'contao/main.php?' . ampersand($objTreeSelector->managerHref) . '&popup=1'; } // Prevent debug output at all cost. $GLOBALS['TL_CONFIG']['debugMode'] = false; $template->output(); }
/** * Run the controller and parse the template */ public function run() { $this->Template = new \BackendTemplate('be_picker'); $this->Template->main = ''; // Ajax request if ($_POST && \Environment::get('isAjaxRequest')) { $this->objAjax = new \Ajax(\Input::post('action')); $this->objAjax->executePreActions(); } $strTable = \Input::get('table'); $strField = \Input::get('field'); // Define the current ID define('CURRENT_ID', \Input::get('table') ? $this->Session->get('CURRENT_ID') : \Input::get('id')); $this->loadDataContainer($strTable); $strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer']; $objDca = new $strDriver($strTable); // AJAX request if ($_POST && \Environment::get('isAjaxRequest')) { $this->objAjax->executePostActions($objDca); } $this->Session->set('treePickerRef', \Environment::get('request')); $objTreeSelector = new $GLOBALS['BE_FFL']['treeSelector'](\Widget::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, array_filter(explode(',', \Input::get('value'))), $strField, $strTable, $objDca)); $this->Template->main = $objTreeSelector->generate(); $this->Template->theme = \Backend::getTheme(); $this->Template->base = \Environment::get('base'); $this->Template->language = $GLOBALS['TL_LANGUAGE']; $this->Template->title = specialchars($GLOBALS['TL_LANG']['MSC']['treepicker']); $this->Template->charset = $GLOBALS['TL_CONFIG']['characterSet']; $this->Template->addSearch = $objTreeSelector->searchField; $this->Template->search = $GLOBALS['TL_LANG']['MSC']['search']; $this->Template->action = ampersand(\Environment::get('request')); $this->Template->value = $this->Session->get($objTreeSelector->getSearchSessionKey()); $this->Template->manager = $GLOBALS['TL_LANG']['MSC']['treepickerManager']; $this->Template->breadcrumb = $GLOBALS['TL_DCA'][$objTreeSelector->foreignTable]['list']['sorting']['breadcrumb']; $this->Template->managerHref = ''; // Add the manager link if ($objTreeSelector->managerHref) { $this->Template->managerHref = 'contao/main.php?' . ampersand($objTreeSelector->managerHref) . '&popup=1&wtp=1'; } $GLOBALS['TL_CONFIG']['debugMode'] = false; $this->Template->output(); }
/** * Generate a filter form */ protected function generateFilters() { $this->Template->hasFilters = false; if (!empty($this->iso_filterFields)) { $arrFilters = array(); $arrInput = \Input::post('filter'); $arrCategories = $this->findCategories(); foreach ($this->iso_filterFields as $strField) { $arrValues = $this->getUsedValuesForAttribute($strField, $arrCategories, $this->iso_newFilter, $this->iso_list_where); if ($this->blnUpdateCache && in_array($arrInput[$strField], $arrValues)) { Isotope::getRequestCache()->setFilterForModule($strField, Filter::attribute($strField)->isEqualTo($arrInput[$strField]), $this->id); } elseif ($this->blnUpdateCache && $arrInput[$strField] == '') { Isotope::getRequestCache()->removeFilterForModule($strField, $this->id); } elseif (($objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id)) !== null && $objFilter->valueNotIn($arrValues)) { // Request cache contains wrong value, delete it! $this->blnUpdateCache = true; Isotope::getRequestCache()->removeFilterForModule($strField, $this->id); RequestCache::deleteById(\Input::get('isorc')); } elseif (!$this->blnUpdateCache) { // Only generate options if we do not reload anyway if (empty($arrValues)) { continue; } $arrData = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField]; // Use the default routine to initialize options data $arrWidget = \Widget::getAttributesFromDca($arrData, $strField); $objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id); if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strField]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) { $arrWidget['options'] = $objAttribute->getOptionsForProductFilter($arrValues); } // Must have options to apply the filter if (!is_array($arrWidget['options'])) { continue; } foreach ($arrWidget['options'] as $k => $option) { if ($option['value'] == '') { $arrWidget['blankOptionLabel'] = $option['label']; unset($arrWidget['options'][$k]); continue; } elseif (!in_array($option['value'], $arrValues) || $option['value'] == '-') { // @deprecated IsotopeAttributeWithOptions::getOptionsForProductFilter already checks this unset($arrWidget['options'][$k]); continue; } $arrWidget['options'][$k]['default'] = null !== $objFilter && $objFilter->valueEquals($option['value']) ? '1' : ''; } // Hide fields with just one option (if enabled) if ($this->iso_filterHideSingle && count($arrWidget['options']) < 2) { continue; } $arrFilters[$strField] = $arrWidget; } } // !HOOK: alter the filters if (isset($GLOBALS['ISO_HOOKS']['generateFilters']) && is_array($GLOBALS['ISO_HOOKS']['generateFilters'])) { foreach ($GLOBALS['ISO_HOOKS']['generateFilters'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrFilters = $objCallback->{$callback}[1]($arrFilters); } } if (!empty($arrFilters)) { $this->Template->hasFilters = true; $this->Template->filterOptions = $arrFilters; } } }
public function generateAjax($strAction, \DataContainer $objDca) { // no tagsinput action --> return if (!$this->isValidAjaxActions($strAction)) { return; } $strField = $objDca->field = \Input::post('name'); \Controller::loadDataContainer($objDca->table); $objActiveRecord = \HeimrichHannot\Haste\Dca\General::getModelInstance($objDca->table, $objDca->id); if ($objActiveRecord === null) { $this->log('No active record for "' . $strField . '" found (possible SQL injection attempt)', __METHOD__, TL_ERROR); header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } $strField = \Input::post('name'); $objDca->activeRecord = $objActiveRecord; $arrData = $GLOBALS['TL_DCA'][$objDca->table]['fields'][$strField]; if (!is_array($arrData)) { $this->log('No valid field configuration (dca) found for "' . $objDca->table . '.' . $strField . '" (possible SQL injection attempt)', __METHOD__, TL_ERROR); header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } $return = ''; switch ($strAction) { case static::ACTION_FETCH_REMOTE_OPTIONS: $objWidget = new \TagsInput(\Widget::getAttributesFromDca($arrData, $strField, $objActiveRecord->{$strField}, $strField, $this->strTable, $objDca)); $return = array_values($objWidget->getRemoteOptionsFromQuery(\Input::post('query'))); break; } die(json_encode($return)); }
/** * Generates the filter */ protected function generateFilter() { $blnShowClear = false; $arrFilters = array(); foreach ($this->iso_filterFields as $strField) { $blnTrail = false; $arrItems = array(); $arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField], $strField); // Use the default routine to initialize options data foreach ($arrWidget['options'] as $option) { $varValue = $option['value']; // skip zero values (includeBlankOption) // @deprecated drop "-" when we only have the database table as options source if ($varValue === '' || $varValue === '-') { continue; } $strFilterKey = $strField . '=' . $varValue; $blnActive = Isotope::getRequestCache()->getFilterForModule($strFilterKey, $this->id) !== null; $blnTrail = $blnActive ? true : $blnTrail; $arrItems[] = array('href' => \Haste\Util\Url::addQueryString('cumulativefilter=' . base64_encode($this->id . ';' . ($blnActive ? 'del' : 'add') . ';' . $strField . ';' . $varValue)), 'class' => $blnActive ? 'active' : '', 'title' => specialchars($option['label']), 'link' => $option['label']); } if (!empty($arrItems) || $this->iso_iso_filterHideSingle && count($arrItems) < 2) { $objClass = RowClass::withKey('class')->addFirstLast(); if ($blnTrail) { $objClass->addCustom('sibling'); } $objClass->applyTo($arrItems); $objTemplate = new \Isotope\Template($this->navigationTpl); $objTemplate->level = 'level_2'; $objTemplate->items = $arrItems; $arrFilters[$strField] = array('label' => $arrWidget['label'], 'subitems' => $objTemplate->parse(), 'isActive' => $blnTrail); $blnShowClear = $blnTrail ? true : $blnShowClear; } } $this->Template->filters = $arrFilters; $this->Template->showClear = $blnShowClear; }
/** * Generate the form to select import source and basic settings and return it as HTML string * @return string */ protected function formImportSource() { $arrSessionData = $this->Session->get('EFG'); $objFileSelector = new \FileTree(\Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_formdata']['fields']['import_source'], 'import_source', null, 'import_source', 'tl_formdata')); // Return form return ' <div id="tl_buttons"> <a href="' . ampersand(str_replace('&key=import', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> <h2 class="sub_headline">' . $GLOBALS['TL_LANG']['tl_formdata']['import'][1] . '</h2> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_formdata_import" class="tl_form" method="post"> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="tl_formdata_import"> <input type="hidden" name="FORM_MODE" value="preview"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <div class="tl_tbox block"> <div class="w50"> <h3><label for="separator">' . $GLOBALS['TL_LANG']['MSC']['separator'][0] . '</label></h3> <select name="separator" id="separator" class="tl_select" onfocus="Backend.getScrollOffset()"> <option value="comma"' . ($arrSessionData['import'][$this->strFormKey]['separator'] == 'comma' ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['comma'] . '</option> <option value="semicolon"' . ($arrSessionData['import'][$this->strFormKey]['separator'] == 'semicolon' || !isset($arrSessionData['import'][$this->strFormKey]['separator']) ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['semicolon'] . '</option> <option value="tabulator"' . ($arrSessionData['import'][$this->strFormKey]['separator'] == 'tabulator' ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['tabulator'] . '</option> </select>' . (strlen($GLOBALS['TL_LANG']['MSC']['separator'][1]) ? ' <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['separator'][1] . '</p>' : '') . ' </div> <div class="w50 m12 cbx"> <div class="tl_checkbox_single_container"> <input name="csv_has_header" id="csv_has_header" type="checkbox" value="1"' . ($arrSessionData['import'][$this->strFormKey]['csv_has_header'] == '1' ? ' checked="checked"' : '') . '> <label for="csv_has_header">' . $GLOBALS['TL_LANG']['tl_formdata']['csv_has_header'][0] . '</label> </div> <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_formdata']['csv_has_header'][1] . '</p> </div> <div class="clr">' . $objFileSelector->parse() . (strlen($GLOBALS['TL_LANG']['tl_formdata']['import_source'][1]) ? ' <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_formdata']['import_source'][1] . '</p>' : '') . ' </div> </div> </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> <input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_formdata']['import'][0]) . '" onfocus="document.cookie = \'BE_PAGE_OFFSET=0; path=/\';"> </div> </div> </form>' . $this->getFilepickerJavascript('reloadEfgImportSource'); }