setParams($params); $this->index = $index; $this->ccontext = $context; Factory::getApplication()->bootComponent('com_visforms'); $this->visforms_version = \plgContentVfdataview::checkVisforms(); } public function getHtml() { $html = ""; if (!isset($this->pparams['formid'])) { return $html; } if (!isset($this->pparams['fieldlist']) || ($this->pparams['fieldlist']) == "") { return $html; } $formid = isset($this->pparams['formid']) ? $this->pparams['formid'] : 0; $this->fixInvalidSortFields(); $context = 'plgvfdataview.' . $this->ccontext . '.' . $formid . '.' . $this->index; $this->rawContext = $context; // Get an instance of the generic visforms data model $model = new VisformsdataModel(array('context' => $context, 'formid' => $formid, 'pparams' => $this->pparams)); $model->setId($formid); $this->mid = $model->getMenuId(); $this->form = $model->getForm(); $allowfedv = (isset($this->form->allowfedv) && $this->form->allowfedv == 1) ? true : false; if ($allowfedv == false) { return $html; } //check if user access level allows view $user = Factory::getApplication()->getIdentity(); $groups = $user->getAuthorisedViewLevels(); $access = (isset($this->form->frontendaccess) && in_array($this->form->frontendaccess, $groups)) ? true : false; if ($access == false) { return $html; } $this->items = $model->getItems(); $error = $model->getError(); if (!empty($error)) { Factory::getApplication()->enqueueMessage(Text::_('PLG_CONTENT_VFDATAVIEW_INVALID_PLUGIN_STRING') . $error, 'error'); return ''; } $this->pagination = $model->getPagination(); $this->showFilter = (isset($this->pparams['show_filter']) && ($this->pparams['show_filter'] == "true")); if ($this->showFilter) { $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); } $this->context = $model->getContext(); $this->hiddenFields = array_map('trim', explode(",", $this->pparams['hidden_fields'])); $this->state = $model->getState(); $this->fields = $model->getDatafields(); //remove fields, that are not selected by plugin parameters from field list $this->getFieldList(); $this->counterOffest = $model->getStart(); $this->total = $model->getTotal(); $this->canDo = \VisformsHelper::getActions($this->form->id); if (isset($this->pparams['layout'])) { $path = PluginHelper::getLayoutPath('content', 'vfdataview', $this->pparams['layout']); } else { $path = PluginHelper::getLayoutPath('content', 'vfdataview'); } ob_start(); include $path; $html = ob_get_clean(); return $html; } private function fixInvalidSortFields() { $db = Factory::getDbo(); $tn = '#__visforms_' . $this->pparams['formid']; try { $tableFields = $db->getTableColumns( $tn, false); if (!array_key_exists($this->pparams['sortorder'], $tableFields) && !array_key_exists('F' . $this->pparams['sortorder'], $tableFields)) { $this->pparams['sortorder'] = 'id'; } } catch (\Exception $ex) { // nothing to do } } private function setParams($params) { // allowed values 'true' or 'false' $defaultsettings = array( "showlabel" => "true", "show_page_heading" => "true", "displayid" => "true", "displayip" => "false", "displayismfd" => "false", "displaycreated" => "false", "displaycreatedtime" => "false", "show_filter" => 'false', "displaydetail" => 'false', "displaydetailtitle" => 'false', "displaymodifiedat" => "false", "displaymodifiedattime" => "false", "displaycounter" => "false", "displaypdfexportbutton" => "false", "show_filter_created" => "false" ); $defaultsettingsNum = array( "formid" => "0", "display_num" => "20", "maxtextlength" => "0"); $defaultsettingsString = array( "hidden_fields" => "", "fieldorder" => "", ); $defaultsettingsCustom = array( "sortorder" => "id", "sortdirection" => "asc" ); if (count($params) > 0) { // sanitize Plugin parameter foreach ($params as $name => $value) { if (array_key_exists($name, $defaultsettings)) { if (!in_array(strtolower($value), array('true', 'false'))) { unset($params[$name]); } } else if (array_key_exists($name, $defaultsettingsNum)) { $regex = '/^\d+$/'; if (!preg_match($regex, $value)) { unset($params[$name]); } } else if (array_key_exists($name, $defaultsettingsString)) { $params[$name] = InputFilter::getInstance()->clean($value); } else if ($name === 'sortdirection') { if (!in_array(strtolower($value), array('asc', 'desc'))) { unset($params[$name]); } } } if (isset($params['fieldselect']) && is_array($params['fieldselect'])) { foreach ($params['fieldselect'] as $fname => $fselect) { $replacedFSelect = $this->replacePlaceholder($fselect); $params['fieldselect'][$fname] = $replacedFSelect; } } } if (count($params) > 0) { $this->pparams = array_merge($defaultsettings, $defaultsettingsNum, $defaultsettingsString, $defaultsettingsCustom, $params); } else { $this->pparams = array_merge($defaultsettings, $defaultsettingsNum, $defaultsettingsString, $defaultsettingsCustom); } } //only use the fields specified in the fieldlist parameter private function getFieldList() { $fieldlist = array_map('trim', explode(",", $this->pparams['fieldlist'])); $n = is_array($this->fields) ? count($this->fields) : 0; $newFieldList = array(); for ($i = 0; $i < $n; $i++) { if ((in_array($this->fields[$i]->id, $fieldlist)) && (isset($this->fields[$i]->frontdisplay) && ($this->fields[$i]->frontdisplay == 1 || $this->fields[$i]->frontdisplay == 2 || $this->fields[$i]->frontdisplay == 3))) { array_push($newFieldList, $this->fields[$i]); } } $this->fields = $newFieldList; } private function replacePlaceholder($placeholder = null) { if (isset($placeholder)) { $user = Factory::getApplication()->getIdentity(); $userId = $user->get('id'); switch ($placeholder) { case "[_url]" : $url = Uri::getInstance()->__toString(); $placeholder = $url; break; case "[_name]": if ($userId != 0) { $placeholder = $user->get('name'); } break; case "[_username]": if ($userId != 0) { $placeholder = $user->get('username'); } break; case "[_email]": if ($userId != 0) { $placeholder = $user->get('email'); } break; default; $placeholder = InputFilter::getInstance()->clean($placeholder); break; } } return $placeholder; } }