public function getFieldSelectOptions($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('a.xml', 'b.name'))); $query->from($db->quoteName('#__componentbuilder_field', 'a')); $query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'b') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('b.id') . ')'); $query->where($db->quoteName('a.published') . ' = 1'); $query->where($db->quoteName('a.id') . ' = ' . (int) $id); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $result = $db->loadObject(); $result->name = strtolower($result->name); if (ComponentbuilderHelper::typeField($result->name, 'list')) { // load the values form params $xml = json_decode($result->xml); $xmlOptions = ComponentbuilderHelper::getBetween($xml, 'option="', '"'); $optionSet = ''; if (strpos($xmlOptions, ',') !== false) { // mulitpal options $options = explode(',', $xmlOptions); foreach ($options as $option) { // return both value and text if (ComponentbuilderHelper::checkString($optionSet)) { // no add to option set $optionSet .= "\n" . $option; } else { // no add to option set $optionSet .= $option; } } } else { // return both value and text if (ComponentbuilderHelper::checkString($optionSet)) { // no add to option set $optionSet .= "\n" . $xmlOptions; } else { // no add to option set $optionSet .= $xmlOptions; } } // return found field options return $optionSet; } elseif (ComponentbuilderHelper::typeField($result->name, 'text')) { return "keywords=\"\"\nlength=\"\""; } elseif (ComponentbuilderHelper::typeField($result->name, 'dynamic')) { return 'dynamic_list'; } elseif (ComponentbuilderHelper::typeField($result->name)) { return 'match field type not supported. Select another!'; } else { return 'dynamic_list'; } } return false; }
public function getValueScript($type, $name, $extends, $unique) { $select = ''; $isArray = false; $keyName = $name . '_' . $unique; if ($type == 'checkboxes' || $extends == 'checkboxes') { $select = "var " . $keyName . " = [];\n\tjQuery('#jform_" . $name . " input[type=checkbox]').each(function()\n\t{\n\t\tif (jQuery(this).is(':checked'))\n\t\t{\n\t\t\t" . $keyName . ".push(jQuery(this).prop('value'));\n\t\t}\n\t});"; $isArray = true; } elseif ($type == 'checkbox') { $select = 'var ' . $keyName . ' = jQuery("#jform_' . $name . '").prop(\'checked\');'; } elseif ($type == 'radio') { $select = 'var ' . $keyName . ' = jQuery("#jform_' . $name . ' input[type=\'radio\']:checked").val();'; } elseif (isset($this->setScriptUserSwitch) && ComponentbuilderHelper::checkArray($this->setScriptUserSwitch) && in_array($type, $this->setScriptUserSwitch)) { // this is only since 3.3.4 $select = 'var ' . $keyName . ' = jQuery("#jform_' . $name . '_id").val();'; } elseif ($type == 'list' || ComponentbuilderHelper::typeField($type, 'dynamic') || !ComponentbuilderHelper::typeField($type)) { $select = 'var ' . $keyName . ' = jQuery("#jform_' . $name . '").val();'; $isArray = true; } elseif (ComponentbuilderHelper::typeField($type, 'text')) { $select = 'var ' . $keyName . ' = jQuery("#jform_' . $name . '").val();'; } return array('get' => $select, 'isArray' => $isArray); }
/** * Get all Admin View Data * * @param int $id The view ID * * @return oject The view data * */ public function getAdminViewData($id) { if (!isset($this->_adminViewData[$id])) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select('a.*'); $query->from('#__componentbuilder_admin_view AS a'); $query->where($db->quoteName('a.id') . ' = ' . (int) $id); // Reset the query using our newly populated query object. $db->setQuery($query); // Load the results as a list of stdClass objects (see later for more options on retrieving data). $view = $db->loadObject(); // reset fields $view->fields = array(); // setup view name to use in storing the data $name_single = ComponentbuilderHelper::safeString($view->name_single); $name_list = ComponentbuilderHelper::safeString($view->name_list); // setup token check $this->customScriptBuilder['token'][$name_single] = false; $this->customScriptBuilder['token'][$name_list] = false; // load the values form params $permissions = json_decode($view->addpermissions, true); unset($view->addpermissions); $tabs = json_decode($view->addtabs, true); unset($view->addtabs); $fields = json_decode($view->addfields, true); unset($view->addfields); $conditions = json_decode($view->addconditions, true); unset($view->addconditions); $linked_views = json_decode($view->addlinked_views, true); unset($view->addlinked_views); $tables = json_decode($view->addtables, true); unset($view->addtables); // sort the values if (ComponentbuilderHelper::checkArray($tables)) { foreach ($tables as $option => $values) { foreach ($values as $nr => $value) { $view->tables[$nr][$option] = $value; } } } if (ComponentbuilderHelper::checkArray($tabs)) { foreach ($tabs as $option => $values) { foreach ($values as $nr => $value) { $fix = $nr + 1; $view->tabs[$fix] = $value; } } } if (ComponentbuilderHelper::checkArray($permissions)) { foreach ($permissions as $option => $values) { foreach ($values as $nr => $value) { $view->permissions[$nr][$option] = $value; } } } if (ComponentbuilderHelper::checkArray($fields)) { foreach ($fields as $option => $values) { foreach ($values as $nr => $value) { $view->fields[$nr][$option] = (int) $value; } } // sort the fields acording to order usort($view->fields, function ($a, $b) { if ($a['order_list'] != 0 && $b['order_list'] != 0) { return $a['order_list'] - $b['order_list']; } elseif ($b['order_list'] != 0 && $a['order_list'] == 0) { return 1; } elseif ($a['order_list'] != 0 && $b['order_list'] == 0) { return 0; } return 1; }); // load the field data foreach ($view->fields as $key => &$field) { $field['settings'] = $this->getFieldData($field['field'], $name_single, $name_list); } } if (ComponentbuilderHelper::checkArray($conditions)) { foreach ($conditions as $condition => $conditionValues) { foreach ($conditionValues as $nr => $conditionValue) { if ($condition == 'target_field') { if (ComponentbuilderHelper::checkArray($conditionValue) && ComponentbuilderHelper::checkArray($view->fields)) { foreach ($conditionValue as $fieldKey => $fieldId) { foreach ($view->fields as $fieldValues) { if ((int) $fieldValues['field'] == (int) $fieldId) { // load the field details $required = ComponentbuilderHelper::getBetween($fieldValues['settings']->xml, 'required="', '"'); $required = $required == true ? 'yes' : 'no'; $filter = ComponentbuilderHelper::getBetween($fieldValues['settings']->xml, 'filter="', '"'); $filter = ComponentbuilderHelper::checkString($filter) ? $filter : 'none'; // get name $name = ComponentbuilderHelper::getBetween($fieldValues['settings']->xml, 'name="', '"'); $name = ComponentbuilderHelper::checkString($name) ? $name : $fieldValues['settings']->name; // get type $type = ComponentbuilderHelper::getBetween($fieldValues['settings']->xml, 'type="', '"'); $type = ComponentbuilderHelper::checkString($type) ? $type : $fieldValues['settings']->type_name; // set the field name $conditionValue[$fieldKey] = array('name' => ComponentbuilderHelper::safeString($name), 'type' => ComponentbuilderHelper::safeString($type), 'required' => $required, 'filter' => $filter); break; } } } } } if ($condition == 'match_field') { foreach ($view->fields as $fieldValue) { if ((int) $fieldValue['field'] == (int) $conditionValue) { // get name $name = ComponentbuilderHelper::getBetween($fieldValue['settings']->xml, 'name="', '"'); $name = ComponentbuilderHelper::checkString($name) ? $name : $fieldValue['settings']->name; // get type $type = ComponentbuilderHelper::getBetween($fieldValue['settings']->xml, 'type="', '"'); $type = ComponentbuilderHelper::checkString($type) ? $type : $fieldValue['settings']->type_name; // set the field details $view->conditions[$nr]['match_name'] = ComponentbuilderHelper::safeString($name); $view->conditions[$nr]['match_type'] = ComponentbuilderHelper::safeString($type); $view->conditions[$nr]['match_xml'] = $fieldValue['settings']->xml; // if custom field load field being extended if (!ComponentbuilderHelper::typeField($type)) { $view->conditions[$nr]['match_extends'] = ComponentbuilderHelper::getBetween($fieldValue['settings']->xml, 'extends="', '"'); } else { $view->conditions[$nr]['match_extends'] = ''; } break; } } } // set condition values $view->conditions[$nr][$condition] = $conditionValue; } } } // set linked views $linked_views_sorted = null; if (ComponentbuilderHelper::checkArray($linked_views)) { $linked_views_sorted = array(); foreach ($linked_views as $option => $values) { foreach ($values as $nr => $value) { $linked_views_sorted[$nr][$option] = $value; } } } unset($linked_views); // setup linked views to global data sets $this->linkedAdminViews[$name_single] = $linked_views_sorted; unset($linked_views_sorted); // set the lang target $this->lang = 'admin'; // add_javascript $addArrayJ = array('javascript_view_file', 'javascript_view_footer', 'javascript_views_file', 'javascript_views_footer'); foreach ($addArrayJ as $scripter) { if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1) { $view->{$scripter} = $this->setCustomContentLang(base64_decode($view->{$scripter})); $scripter_target = str_replace('javascript_', '', $scripter); if (!isset($this->customScriptBuilder[$scripter_target][$name_single])) { if (!isset($this->customScriptBuilder[$scripter_target])) { $this->customScriptBuilder[$scripter_target] = array(); } $this->customScriptBuilder[$scripter_target][$name_single] = ''; } $this->customScriptBuilder[$scripter_target][$name_single] .= $view->{$scripter}; if (strpos($view->{$scripter}, "token") !== false && strpos($view->{$scripter}, "task=ajax") !== false) { if (!$this->customScriptBuilder['token'][$name_single]) { $this->customScriptBuilder['token'][$name_single] = true; } } unset($view->{$scripter}); } } // add_css $addArrayC = array('css_view', 'css_views'); foreach ($addArrayC as $scripter) { if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1) { if (!isset($this->customScriptBuilder[$scripter][$name_single])) { $this->customScriptBuilder[$scripter][$name_single] = ''; } $this->customScriptBuilder[$scripter][$name_single] .= base64_decode($view->{$scripter}); unset($view->{$scripter}); } } // add_php $addArrayP = array('php_getitem', 'php_save', 'php_postsavehook', 'php_getitems', 'php_getitems_after_all', 'php_getlistquery', 'php_allowedit', 'php_before_delete', 'php_after_delete', 'php_before_publish', 'php_after_publish', 'php_batchcopy', 'php_batchmove', 'php_document'); foreach ($addArrayP as $scripter) { if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1) { $this->customScriptBuilder[$scripter][$name_single] = $this->setCustomContentLang(base64_decode($view->{$scripter})); unset($view->{$scripter}); } } // add the custom buttons if (isset($view->add_custom_button) && $view->add_custom_button == 1) { if (ComponentbuilderHelper::checkString($view->php_model)) { $view->php_model = base64_decode($view->php_model); $view->php_model = $this->setCustomContentLang($view->php_model); } $view->php_controller = base64_decode($view->php_controller); $view->php_controller = $this->setCustomContentLang($view->php_controller); // set the button array $buttons = json_decode($view->custom_button, true); unset($view->custom_button); // sort the values if (ComponentbuilderHelper::checkArray($buttons)) { foreach ($buttons as $option => $values) { foreach ($values as $nr => $value) { $view->custom_buttons[$nr][$option] = $value; } } } } // set custom import scripts if (isset($view->add_custom_import) && $view->add_custom_import == 1) { $addImportArray = array('php_import_display', 'php_import', 'php_import_setdata', 'php_import_save', 'html_import_view'); foreach ($addImportArray as $importScripter) { if (isset($view->{$importScripter}) && strlen($view->{$importScripter}) > 0) { $this->customScriptBuilder[$importScripter]['import_' . $name_list] = $this->setCustomContentLang(base64_decode($view->{$importScripter})); unset($view->{$importScripter}); } } } // add_Ajax for this view if (isset($view->add_php_ajax) && $view->add_php_ajax == 1) { $addAjaxSite = false; if (isset($this->siteEditView[$id]) && $this->siteEditView[$id]) { // we should add this site ajax to fron ajax $addAjaxSite = true; if (!isset($this->addSiteAjax) || !$this->addSiteAjax) { $this->addSiteAjax = true; } } // check if controller input as been set $ajax_input = json_decode($view->ajax_input, true); if (ComponentbuilderHelper::checkArray($ajax_input)) { foreach ($ajax_input as $option => $values) { foreach ($values as $nr => $value) { if ($addAjaxSite) { $this->customScriptBuilder['site']['ajax_controller'][$name_single][$nr][$option] = $value; } $this->customScriptBuilder['admin']['ajax_controller'][$name_single][$nr][$option] = $value; } } $this->addAjax = true; unset($view->ajax_input); } if (ComponentbuilderHelper::checkString($view->php_ajaxmethod)) { if ($addAjaxSite) { $this->customScriptBuilder['site']['ajax_model'][$name_single] = $this->setCustomContentLang(base64_decode($view->php_ajaxmethod)); } $this->customScriptBuilder['admin']['ajax_model'][$name_single] = $this->setCustomContentLang(base64_decode($view->php_ajaxmethod)); // unset anyway unset($view->php_ajaxmethod); $this->addAjax = true; } } // add_sql if ($view->add_sql == 1) { if ($view->source == 1) { // build and add the SQL dump $this->customScriptBuilder['sql'][$name_single] = $this->buildSqlDump($view->tables, $name_single, $id); unset($view->tables); } elseif ($view->source == 2) { // add the SQL dump string $this->customScriptBuilder['sql'][$name_single] = base64_decode($view->sql); unset($view->sql); } } $this->_adminViewData[$id] = $view; } // return the found view data return $this->_adminViewData[$id]; }