/** * Make a group object to be used in the form view. Object contains * group display properties * * @param object &$formModel form model * * @return object group display properties */ public function getGroupProperties(&$formModel) { $w = new FabrikWorker(); $input = $this->app->input; $group = new stdClass(); $groupTable = $this->getGroup(); $params = $this->getParams(); $view = $input->get('view'); if (!isset($this->editable)) { $this->editable = $formModel->isEditable(); } if ($this->editable) { // If all of the groups elements are not editable then set the group to uneditable $elements = $this->getPublishedElements(); $editable = false; foreach ($elements as $element) { if ($element->canUse()) { $editable = true; } } if (!$editable) { $this->editable = false; } } $group->editable = $this->editable; $group->canRepeat = $params->get('repeat_group_button', '0'); $showGroup = $params->def('repeat_group_show_first', '1'); $pages = $formModel->getPages(); $startPage = isset($formModel->sessionModel->last_page) ? $formModel->sessionModel->last_page : 0; /** * $$$ hugh - added array_key_exists for (I think!) corner case where group properties have been * changed to remove (or change) paging, but user still has session state set. So it was throwing * a PHP 'undefined index' notice. */ if (array_key_exists($startPage, $pages) && is_array($pages[$startPage]) && !in_array($groupTable->id, $pages[$startPage]) || $showGroup == -1 || $showGroup == 0 || $view == 'form' && $showGroup == -2 || $view == 'details' && $showGroup == -3) { $groupTable->css .= ";display:none;"; } $group->css = trim(str_replace(array("<br />", "<br>"), "", $groupTable->css)); $group->id = $groupTable->id; $label = $input->getString('group' . $group->id . '_label', $groupTable->label); if (JString::stristr($label, "{Add/Edit}")) { $replace = $formModel->isNewRecord() ? FText::_('COM_FABRIK_ADD') : FText::_('COM_FABRIK_EDIT'); $label = str_replace("{Add/Edit}", $replace, $label); } $groupTable->label = $label; $group->title = $w->parseMessageForPlaceHolder($groupTable->label, $formModel->data, false); $group->title = FText::_($group->title); $group->name = $groupTable->name; $group->displaystate = $group->canRepeat == 1 && $formModel->isEditable() ? 1 : 0; $group->maxRepeat = (int) $params->get('repeat_max'); $group->minRepeat = $params->get('repeat_min', '') === '' ? 1 : (int) $params->get('repeat_min', ''); $group->showMaxRepeats = $params->get('show_repeat_max', '0') == '1'; $group->minMaxErrMsg = $params->get('repeat_error_message', ''); $group->minMaxErrMsg = FText::_($group->minMaxErrMsg); $group->canAddRepeat = $this->canAddRepeat(); $group->canDeleteRepeat = $this->canDeleteRepeat(); $group->intro = $text = FabrikString::translate($params->get('intro')); $group->outro = FText::_($params->get('outro')); $group->columns = $params->get('group_columns', 1); $group->splitPage = $params->get('split_page', 0); $group->showLegend = $this->showLegend($group); $group->labels = $params->get('labels_above', -1); $group->dlabels = $params->get('labels_above_details', -1); if ($this->canRepeat()) { $group->tmpl = $params->get('repeat_template', 'repeatgroup'); } else { $group->tmpl = 'group'; } return $group; }
/** * Display the template * * @param sting $tpl template * * @return void */ public function display($tpl = null) { if ($this->getLayout() == '_advancedsearch') { $this->advancedSearch($tpl); return; } $fbConfig = JComponentHelper::getParams('com_fabrik'); $profiler = JProfiler::getInstance('Application'); $app = JFactory::getApplication(); $input = $app->input; $model = $this->getModel(); // Force front end templates $tmpl = $model->getTmpl(); $this->_basePath = COM_FABRIK_FRONTEND . '/views'; $jTmplFolder = FabrikWorker::j3() ? 'tmpl' : 'tmpl25'; $this->addTemplatePath($this->_basePath . '/' . $this->_name . '/' . $jTmplFolder . '/' . $tmpl); $root = $app->isAdmin() ? JPATH_ADMINISTRATOR : JPATH_SITE; $this->addTemplatePath($root . '/templates/' . $app->getTemplate() . '/html/com_fabrik/list/' . $tmpl); $user = JFactory::getUser(); $document = JFactory::getDocument(); $item = $model->getTable(); $data = $model->render(); $w = new FabrikWorker(); // Add in some styling short cuts $c = 0; $form = $model->getFormModel(); $nav = $model->getPagination(); foreach ($data as $groupk => $group) { $last_pk = ''; $last_i = 0; $num_rows = 1; foreach (array_keys($group) as $i) { $o = new stdClass(); // $$$ rob moved merge wip code to FabrikModelTable::formatForJoins() - should contain fix for pagination $o->data = $data[$groupk][$i]; $o->cursor = $num_rows + $nav->limitstart; $o->total = $nav->total; $o->id = 'list_' . $model->getRenderContext() . '_row_' . @$o->data->__pk_val; $o->class = 'fabrik_row oddRow' . $c; $data[$groupk][$i] = $o; $c = 1 - $c; $num_rows++; } } $groups = $form->getGroupsHiarachy(); foreach ($groups as $groupModel) { $elementModels = $groupModel->getPublishedElements(); foreach ($elementModels as $elementModel) { $elementModel->setContext($groupModel, $form, $model); $rowclass = $elementModel->setRowClass($data); } } $this->rows = $data; reset($this->rows); // Cant use numeric key '0' as group by uses grouped name as key $firstRow = current($this->rows); $this->requiredFiltersFound = $model->getRequiredFiltersFound(); $this->advancedSearch = $model->getAdvancedSearchLink(); $this->advancedSearchURL = $model->getAdvancedSearchURL(); $this->nodata = empty($this->rows) || count($this->rows) == 1 && empty($firstRow) || !$this->requiredFiltersFound ? true : false; $this->tableStyle = $this->nodata ? 'display:none' : ''; $this->emptyStyle = $this->nodata ? '' : 'display:none'; $params = $model->getParams(); if (!$this->access($model)) { return false; } if (!class_exists('JSite')) { require_once JPATH_ROOT . '/includes/application.php'; } $app = JFactory::getApplication(); $package = $app->getUserState('com_fabrik.package', 'fabrik'); $this->setTitle($w, $params, $model); // Deprecated (keep in case people use them in old templates) $this->table = new stdClass(); $this->table->label = FabrikString::translate($w->parseMessageForPlaceHolder($item->label, $_REQUEST)); $this->table->intro = $params->get('show_into', 1) == 0 ? '' : FabrikString::translate($w->parseMessageForPlaceHolder($item->introduction)); $this->table->outro = $params->get('show_outro', 1) == 0 ? '' : FabrikString::translate($w->parseMessageForPlaceHolder($params->get('outro'))); $this->table->id = $item->id; $this->table->renderid = $model->getRenderContext(); $this->table->db_table_name = $item->db_table_name; // End deprecated $this->list = $this->table; $this->list->class = $model->htmlClass(); $this->group_by = $item->group_by; $this->form = new stdClass(); $this->form->id = $item->form_id; $this->renderContext = $model->getRenderContext(); $this->formid = 'listform_' . $this->renderContext; $form = $model->getFormModel(); $this->table->action = $model->getTableAction(); $this->showCSV = $model->canCSVExport(); $this->showCSVImport = $model->canCSVImport(); $this->toggleCols = $model->toggleCols(); $this->showToggleCols = (bool) $params->get('toggle_cols', false); $this->canGroupBy = $model->canGroupBy(); $this->navigation = $nav; $this->nav = $input->getInt('fabrik_show_nav', $params->get('show-table-nav', 1)) ? $nav->getListFooter($this->renderContext, $model->getTmpl()) : ''; $this->nav = '<div class="fabrikNav">' . $this->nav . '</div>'; $this->fabrik_userid = $user->get('id'); $this->canDelete = $model->deletePossible() ? true : false; $this->limitLength = $model->limitLength; $this->ajax = $model->isAjax(); // 3.0 observed in list.js & html moved into fabrik_actions rollover $this->showPDF = $params->get('pdf', $fbConfig->get('list_pdf', false)); if ($this->showPDF) { FabrikWorker::canPdf(); } $this->emptyLink = $model->canEmpty() ? '#' : ''; $this->csvImportLink = $this->showCSVImport ? JRoute::_('index.php?option=com_' . $package . '&view=import&filetype=csv&listid=' . $item->id) : ''; $this->showAdd = $model->canAdd(); if ($this->showAdd) { if ($params->get('show-table-add', 1)) { $this->addRecordLink = $model->getAddRecordLink(); } else { $this->showAdd = false; } } $this->addLabel = $model->addLabel(); $this->showRSS = $params->get('rss', 0) == 0 ? 0 : 1; if ($this->showRSS) { $this->rssLink = $model->getRSSFeedLink(); if ($this->rssLink != '') { $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); $document->addHeadLink($this->rssLink, 'alternate', 'rel', $attribs); } } if ($app->isAdmin()) { // Admin always uses com_fabrik option $this->pdfLink = JRoute::_('index.php?option=com_fabrik&task=list.view&listid=' . $item->id . '&format=pdf&tmpl=component'); } else { $pdfLink = 'index.php?option=com_' . $package . '&view=list&format=pdf&listid=' . $item->id; if (!$this->nodata) { // If some data is shown then ensure that menu links reset filters (combined with require filters) doesn't produce an empty data set for the pdf $pdfLink .= '&resetfilters=0'; } $this->pdfLink = JRoute::_($pdfLink); } list($this->headings, $groupHeadings, $this->headingClass, $this->cellClass) = $model->getHeadings(); $this->groupByHeadings = $model->getGroupByHeadings(); $this->filter_action = $model->getFilterAction(); JDEBUG ? $profiler->mark('fabrik getfilters start') : null; $this->filters = $model->getFilters('listform_' . $this->renderContext); $fKeys = array_keys($this->filters); $this->bootShowFilters = count($fKeys) === 1 && $fKeys[0] === 'all' ? false : true; $this->clearFliterLink = $model->getClearButton(); JDEBUG ? $profiler->mark('fabrik getfilters end') : null; $this->filterMode = (int) $params->get('show-table-filters'); $this->toggleFilters = $this->filterMode == 2 || $this->filterMode == 4; $this->showFilters = $model->getShowFilters(); $this->filterCols = (int) $params->get('list_filter_cols', '1'); $this->showClearFilters = $this->showFilters || $params->get('advanced-filter') ? true : false; $this->emptyDataMessage = $model->getEmptyDataMsg(); $this->groupheadings = $groupHeadings; $this->calculations = $this->_getCalculations($this->headings); $this->isGrouped = !($model->getGroupBy() == ''); $this->colCount = count($this->headings); $this->hasButtons = $model->getHasButtons(); $this->grouptemplates = $model->groupTemplates; $this->params = $params; $this->loadTemplateBottom(); $this->getManagementJS($this->rows); // Get dropdown list of other tables for quick nav in admin $this->tablePicker = $app->isAdmin() && $app->input->get('format') !== 'pdf' ? FabrikHelperHTML::tableList($this->table->id) : ''; $this->buttons(); $this->pluginTopButtons = $model->getPluginTopButtons(); }
/** * Parse into and outro text * * @param string $text Text to parse * * @since 3.0.7 * * @return string */ protected function parseIntroOutroPlaceHolders($text) { if (!$this->isEditable()) { $remove = "/{new:\\s*.*?}/is"; $text = preg_replace($remove, '', $text); $remove = "/{edit:\\s*.*?}/is"; $text = preg_replace($remove, '', $text); $match = "/{details:\\s*.*?}/is"; $text = preg_replace_callback($match, array($this, '_getIntroOutro'), $text); } else { $match = $this->isNewRecord() ? 'new' : 'edit'; $remove = $this->isNewRecord() ? 'edit' : 'new'; $match = "/{" . $match . ":\\s*.*?}/is"; $remove = "/{" . $remove . ":\\s*.*?}/is"; $text = preg_replace_callback($match, array($this, '_getIntroOutro'), $text); $text = preg_replace($remove, '', $text); $text = preg_replace("/{details:\\s*.*?}/is", '', $text); } $w = new FabrikWorker(); $text = $w->parseMessageForPlaceHolder($text, $this->data, true); // Jaanus: to remove content plugin code from intro and/or outro when plugins are not processed $params = $this->getParams(); $jPlugins = (int) $params->get('process-jplugins', '2'); if ($jPlugins === 0 || $jPlugins === 2 && $this->isEditable()) { $text = preg_replace("/{\\s*.*?}/i", '', $text); } $text = FabrikString::translate($text); return $text; }