public function getFieldType($typeName, $xml, $property) { // make sure its lower case $typeName = ComponentbuilderHelper::safeString($typeName); if ($typeName == 'custom' || $typeName == 'customuser') { $xmlValue = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($xml, 'type="', '"')); } elseif (ComponentbuilderHelper::checkString($typeName)) { $xmlValue = $typeName; } elseif (isset($property['example']) && ComponentbuilderHelper::checkString($property['example']) && $property['adjustable'] == 0) { $xmlValue = $property['example']; } else { $xmlValue = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($xml, 'type="', '"')); } // check if the value is set if (ComponentbuilderHelper::checkString($xmlValue)) { // add the value return $xmlValue; } else { // fall back to text return 'text'; } }
protected function getFieldData($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Order it by the ordering field. $query->select($db->quoteName(array('a.name', 'a.xml'))); $query->select($db->quoteName(array('c.name'), array('type_name'))); $query->from('#__componentbuilder_field AS a'); $query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'c') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('c.id') . ')'); $query->where($db->quoteName('a.id') . ' = ' . $db->quote($id)); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { // Load the results as a list of stdClass objects (see later for more options on retrieving data). $field = $db->loadObject(); // load the values form params $field->xml = json_decode($field->xml); $field->type_name = ComponentbuilderHelper::safeString($field->type_name); $load = true; // if category then name must be catid (only one per view) if ($field->type_name == 'category') { $name = 'catid'; } elseif ($field->type_name == 'tag') { $name = 'tags'; } elseif ($field->type_name == 'spacer' || $field->type_name == 'note') { // make sure the name is unique return false; } else { $name = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field->xml, 'name="', '"')); } // use field core name only if not found in xml if (!ComponentbuilderHelper::checkString($name)) { $name = ComponentbuilderHelper::safeString($field->name); } return array('name' => $name, 'type' => $field->type_name); } return false; }
/** * set field attributes * * @param array $field The field data * @param int $viewType The view type * @param string $name The field name * @param string $typeName The field type * @param boolean $multiple The switch to set multiple selection option * @param string $langLabel The language string for field label * @param string $langView The language string of the view * @param string $spacerCounter The space counter value * @param string $listViewName The list view name * @param string $viewName The singel view name * @param array $placeholders The place holder and replace values * @param boolean $repeatable The repeatable field switch * * @return array The field attributes * */ private function setFieldAttributes(&$field, &$viewType, &$name, &$typeName, &$multiple, &$langLabel, $langView, &$spacerCounter, $listViewName, $viewName, $placeholders, $repeatable = false) { // reset array` $fieldAttributes = array(); $setCustom = false; // setup joomla default fields if (!$this->defaultField($typeName)) { $fieldAttributes['custom'] = array(); $setCustom = true; } // setup a default field if (ComponentbuilderHelper::checkArray($field['settings']->properties)) { foreach ($field['settings']->properties as $property) { // reset $xmlValue = ''; $langValue = ''; if ($property['name'] == 'type') { if ($typeName == 'custom' || $typeName == 'customuser') { $xmlValue = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'type="', '"')); } elseif (ComponentbuilderHelper::checkString($typeName)) { $xmlValue = $typeName; } elseif (isset($property['example']) && ComponentbuilderHelper::checkString($property['example']) && $property['adjustable'] == 0) { $xmlValue = $property['example']; } else { $xmlValue = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'type="', '"')); } // check if the value is set if (ComponentbuilderHelper::checkString($xmlValue)) { // add the value $typeName = $xmlValue; } else { // fall back to text $xmlValue = 'text'; $typeName = $xmlValue; } // add to custom if it is custom if ($setCustom) { // set the type just to make sure. $fieldAttributes['custom']['type'] = $typeName; } } elseif ($property['name'] == 'name') { // if category then name must be catid (only one per view) if ($typeName == 'category') { // quick check if this is a category linked to view page $requeSt_id = ComponentbuilderHelper::getBetween($field['settings']->xml, 'name="', '"'); if (strpos($requeSt_id, '_request_id') !== false) { // keep it then, don't change $xmlValue = $requeSt_id; } else { $xmlValue = 'catid'; } // check if we should use another Text Name as this views name $otherName = ComponentbuilderHelper::getBetween($field['settings']->xml, 'othername="', '"'); $otherViews = ComponentbuilderHelper::getBetween($field['settings']->xml, 'views="', '"'); $otherView = ComponentbuilderHelper::getBetween($field['settings']->xml, 'view="', '"'); if (ComponentbuilderHelper::checkString($otherName) && ComponentbuilderHelper::checkString($otherViews) && ComponentbuilderHelper::checkString($otherView)) { $this->catOtherName[$listViewName] = array('name' => ComponentbuilderHelper::safeString($otherName), 'views' => ComponentbuilderHelper::safeString($otherViews), 'view' => ComponentbuilderHelper::safeString($otherView)); } } elseif ($typeName == 'tag') { $xmlValue = 'tags'; } elseif (isset($field['alias']) && $field['alias']) { $xmlValue = 'alias'; } elseif ($typeName == 'spacer') { // make sure the name is unique $xmlValue = $name . '_' . $spacerCounter; } else { $xmlValue = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'name="', '"')); } // use field core name only if not found in xml if (!ComponentbuilderHelper::checkString($xmlValue)) { $xmlValue = $name; } else { $name = $xmlValue; } } elseif ($property['name'] == 'extension' || $property['name'] == 'directory') { $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); // replace the placeholders $xmlValue = str_replace(array_keys($placeholders), array_values($placeholders), $xmlValue); } elseif (strpos($property['name'], 'type_php_') !== false && $setCustom) { // set the line number $phpLine = (int) str_replace('type_php_', '', $property['name']); // load the php for the custom field file $fieldAttributes['custom']['php'][$phpLine] = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); } elseif (strpos($property['name'], 'type_phpx_') !== false && $setCustom) { // set the line number $phpLine = (int) str_replace('type_phpx_', '', $property['name']); // load the php for the custom field file $fieldAttributes['custom']['phpx'][$phpLine] = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); } elseif ($property['name'] == 'extends' && $setCustom) { // load the class that is being extended $fieldAttributes['custom']['extends'] = ComponentbuilderHelper::getBetween($field['settings']->xml, 'extends="', '"'); } elseif ($property['name'] == 'view' && $setCustom) { // load the view name $fieldAttributes['custom']['view'] = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'view="', '"')); } elseif ($property['name'] == 'views' && $setCustom) { // load the views name $fieldAttributes['custom']['views'] = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'views="', '"')); } elseif ($property['name'] == 'component' && $setCustom) { // load the component name $fieldAttributes['custom']['component'] = ComponentbuilderHelper::getBetween($field['settings']->xml, 'component="', '"'); // replace the placeholders $fieldAttributes['custom']['component'] = str_replace(array_keys($placeholders), array_values($placeholders), $fieldAttributes['custom']['component']); } elseif ($property['name'] == 'table' && $setCustom) { // load the main table that is queried $fieldAttributes['custom']['table'] = ComponentbuilderHelper::getBetween($field['settings']->xml, 'table="', '"'); // replace the placeholders $fieldAttributes['custom']['table'] = str_replace(array_keys($placeholders), array_values($placeholders), $fieldAttributes['custom']['table']); } elseif ($property['name'] == 'value_field' && $setCustom) { // load the text key $fieldAttributes['custom']['text'] = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'value_field="', '"')); } elseif ($property['name'] == 'key_field' && $setCustom) { // load the id key $fieldAttributes['custom']['id'] = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'key_field="', '"')); } elseif ($property['name'] == 'button' && $repeatable && $setCustom) { // dont load the button to repeatable $xmlValue = 'false'; } elseif ($property['name'] == 'required' && $repeatable) { // dont load the required to repeatable $xmlValue = 'false'; } elseif ($viewType == 2 && ($property['name'] == 'readonly' || $property['name'] == 'disabled')) { // set read only $xmlValue = 'true'; } elseif ($property['name'] == 'multiple') { $xmlValue = (string) ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); // add the multipal if ('true' == $xmlValue) { $multiple = true; } } elseif ($property['name'] == 'class' && ($typeName == 'note' || $typeName == 'spacer')) { $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, 'class="', '"'); // add the type class if (ComponentbuilderHelper::checkString($xmlValue)) { if (strpos($xmlValue, $name) === false) { $xmlValue = $xmlValue . ' ' . $name; } } else { $xmlValue = $name; } } else { // set the rest of the fields $xmlValue = (string) ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); } // check if translatable if (ComponentbuilderHelper::checkString($xmlValue) && $property['translatable'] == 1) { // replace placeholders $xmlValue = str_replace(array_keys($placeholders), array_values($placeholders), $xmlValue); // insure custom lables dont get messed up if ($setCustom) { $customLabel = $xmlValue; } // set lang key $langValue = $langView . '_' . ComponentbuilderHelper::safeString($name . ' ' . $property['name'], 'U'); // add to lang array $this->langContent[$this->lang][$langValue] = $xmlValue; // use lang value $xmlValue = $langValue; } elseif (isset($field['alias']) && $field['alias'] && $property['translatable'] == 1) { if ($property['name'] == 'label') { $xmlValue = 'JFIELD_ALIAS_LABEL'; } elseif ($property['name'] == 'description') { $xmlValue = 'JFIELD_ALIAS_DESC'; } elseif ($property['name'] == 'hint') { $xmlValue = 'JFIELD_ALIAS_PLACEHOLDER'; } } elseif (isset($field['title']) && $field['title'] && $property['translatable'] == 1) { if ($property['name'] == 'label') { $xmlValue = 'JGLOBAL_TITLE'; } elseif ($property['name'] == 'description') { $xmlValue = 'JFIELD_TITLE_DESC'; } } // only load value if found or is mandatory if (ComponentbuilderHelper::checkString($xmlValue) || $property['mandatory'] == 1 && !$setCustom) { // make sure mantory fields are added if (!ComponentbuilderHelper::checkString($xmlValue)) { if (isset($property['example']) && ComponentbuilderHelper::checkString($property['example'])) { $xmlValue = $property['example']; } } $fieldAttributes[$property['name']] = $xmlValue; // load to langBuilder down the line if ($property['name'] == 'label') { $langLabel = $xmlValue; if ($setCustom) { $fieldAttributes['custom']['label'] = $customLabel; } } } } // do some nice twigs beyond the default if (isset($fieldAttributes['name'])) { // check if we find reason to remove this field from being escaped $escaped = ComponentbuilderHelper::getBetween($field['settings']->xml, 'escape="', '"'); if (ComponentbuilderHelper::checkString($escaped)) { $this->doNotEscape[$listViewName][] = $fieldAttributes['name']; } } } return $fieldAttributes; }
/** * 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]; }