/** * Loads tab XML (backend use only!) * (used in TabTable only) * * @param TabTable $tab * @return SimpleXMLElement */ public function _loadTabXML($tab) { if ($this->_tabXml === null) { if ($this->_loadXML($tab)) { $fieldTypesXML = $this->_xml->getElementByPath('tabs'); if ($fieldTypesXML) { $this->_tabXml = $fieldTypesXML->getChildByNameAttr('tab', 'class', $tab->pluginclass); } } } return $this->_tabXml; }
/** * Renders the orderby field html * * @return string The HTML rendering for the orderby field */ function orderbyfields() { /** @var SimpleXMLElement $orderbyFields */ $orderbyFields = $this->_tableBrowserModel->getElementByPath('orderby'); $orderbyOptions = array(); $orderbyOptions[] = moscomprofilerHTML::makeOption('', CBTxt::T('- Select Sort By -')); foreach ($orderbyFields as $orderbyField) { /** @var SimpleXMLElement $orderbyField */ if ($orderbyField->getName() == 'ordergroup') { $val = $orderbyField->attributes('name'); $label = CBTxt::T($orderbyField->attributes('label')); $orderbyOptions[] = moscomprofilerHTML::makeOption($val, $label !== '' ? $label : $val); } } if ($this->pageNav !== null) { $orderbyJS = $this->pageNav->limitstartJs(0); } else { $orderbyJS = 'cbParentForm(this).submit();'; } return moscomprofilerHTML::selectList($orderbyOptions, $this->fieldName('orderby'), 'class="form-control" onchange="' . htmlspecialchars($orderbyJS) . '"', 'value', 'text', $this->fieldValue('orderby'), 0, true, null, false); }
/** * Loads fields-params XML (backend use only!) * also sets $this->_fieldXML and $this->_specific * * @return boolean TRUE if success, FALSE if not existant */ protected function _loadFieldParamsXML() { if ($this->_fieldXml === null) { if ($this->_loadXML()) { $fieldsParamsXML = $this->_xml->getElementByPath('fieldsparams'); if ($fieldsParamsXML) { $fieldTypeSpecific = $fieldsParamsXML->getChildByNameAttr('field', 'type', $this->_field->type); if ($fieldTypeSpecific) { // <fieldsparams><field type="date"><params><param .... $this->_fieldXml =& $fieldTypeSpecific; $this->_specific = true; } else { // <fieldsparams><field type="other_types"><params><param .... $nonSpecific = $fieldsParamsXML->getChildByNameAttr('field', 'type', 'other_types'); if ($nonSpecific) { $this->_fieldXml =& $nonSpecific; $this->_specific = false; } } } } } return $this->_fieldXml !== null; }
/** * Check or fix field according to XML description if exsitant (or old method otherwise) * * @param DatabaseUpgrade $sqlUpgrader * @param FieldTable $field * @param boolean $change * @return boolean */ public function checkFixSQL($sqlUpgrader, $field, $change = true) { $fieldXML =& $this->_loadFieldXML($field); if ($fieldXML) { $db = $fieldXML->getElementByPath('database'); if ($db !== false) { // <database><table><columns>.... structure: $success = $sqlUpgrader->checkXmlDatabaseDescription($db, $field->name, $change, null); } else { $data = $fieldXML->getElementByPath('data'); if ($data !== false) { // <data ....> structure: $xmlText = '<?xml version="1.0" encoding="UTF-8"?>' . '<database version="1">' . '<table name="' . $field->table . '" maintable="true" strict="false" drop="never" shared="true">' . '<columns>' . '</columns>' . '</table>' . '</database>'; $dbXml = new SimpleXMLElement($xmlText); $columns = $dbXml->getElementByPath('table/columns'); $columns->addChildWithAttr('column', '', null, $data->attributes()); $success = $sqlUpgrader->checkXmlDatabaseDescription($dbXml, $field->name, $change, null); } else { $success = true; } } } else { // no XML file or no <fieldtype> in xml, must be an old plugin or one which is uninstalled or missing files: $cols = $field->getTableColumns(); if (count($cols) == 0) { // the comprofiler_files database is upgraded, but this (status) field does not require comprofiler entries: $success = true; } else { // database has been upgraded, take a guess and take first column name as name of the comprofiler table: // or database has not been upgraded: take name: $colNamePrefix = $cols[0]; $xmlText = '<?xml version="1.0" encoding="UTF-8"?>' . '<database version="1">' . '<table name="#__comprofiler" class="\\CB\\Database\\Table\\ComprofilerTable" maintable="true" strict="false" drop="never" shared="true">' . '<columns>' . '<column name="" nametype="namesuffix" type="sql:text||sql:varchar(255)" null="true" default="NULL" />' . '</columns>' . '</table>' . '</database>'; $dbXml = new SimpleXMLElement($xmlText); $success = $sqlUpgrader->checkXmlDatabaseDescription($dbXml, $colNamePrefix, $change, null); } } if (!$success) { // Temporary way to workaround _error protected, as this whole function should probably go to to new FieldModel: $field->set('_error', $sqlUpgrader->getErrors()); } /* var_dump( $success ); echo "<br>\nERRORS: " . $sqlUpgrader->getErrors( "<br /><br />\n\n", "<br />\n" ); echo "<br>\nLOGS: " . $sqlUpgrader->getLogs( "<br /><br />\n\n", "<br />\n" ); //exit; */ return $success; }
/** * parses xml for backend plugin management menu display * * @param null|PluginTable|int $plugin * @return array */ public function getPluginBackendMenu($plugin) { global $_CB_framework; $plugin = $this->getCachedPluginObject($plugin); if (!$plugin) { return false; } static $cache = array(); $pluginId = (int) $plugin->id; if (!isset($cache[$pluginId])) { $menus = array(); // Lets parse the XML file for backend menu items and exclude duplicates added by legacy: $xmlFile = $this->getPluginXmlPath($plugin); if (file_exists($xmlFile)) { $xml = new SimpleXMLElement(trim(file_get_contents($xmlFile))); if ($xml !== null) { $menu = $xml->getElementByPath('adminmenus'); if ($menu !== false) { if (count($menu->children()) > 0) { foreach ($menu->children() as $menuItem) { $menuItemTask = $menuItem->attributes('action'); if (!array_key_exists($menuItemTask, $menus)) { $menus[$menuItemTask] = array($menuItem->data(), $_CB_framework->backendUrl('index.php?option=com_comprofiler&view=pluginmenu&pluginid=' . (int) $plugin->id . '&menu=' . urlencode($menuItemTask), false)); } } } } } } $cache[$pluginId] = $menus; } return $cache[$pluginId]; }
/** * Parse the ticks to plot * @access private * * @param SimpleXMLElement $el <ticks type="function" name="nameofJSfunction" /> * @param callback $callBacks * @return array */ function _plot_parseTickFormatter( &$el, &$callBacks ) { global $_CB_database; $names_values = array(); if ( $el ) { $type = $el->attributes( 'type' ); $data = $el->getElementByPath( 'field' ); if ( ($type == 'append' ) && $data ) { $dataTable = $data->attributes( 'table' ); if ( ! $dataTable ) { $dataTable = null; } $xmlsql = new XmlQuery( $_CB_database, $dataTable, $this->_pluginParams ); $xmlsql->setExternalDataTypeValues( 'modelofdata', $this->_modelOfData[0] ); $xmlsql->process_data( $data ); $textToAppend = $xmlsql->queryloadResult( $data ); // get the records if ( $textToAppend ) { $names_values = new PlotJsonFormatter( 'function(val, axis) { return val.toFixed(axis.tickDecimals)+" ' . addslashes( CBTxt::T( $textToAppend ) ) . '"; }' ); } } else { $callBacksNew = $callBacks; unset( $callBacksNew[$el->getName()] ); $names_values = $this->xml2arr( $el, $callBacksNew ); } } return $names_values; }
/** * Generic function to get an array of option values for lists, radios, checkboxes params and filter fields: * * @param SimpleXMLElement $o * @param string $basetype RETURNED: base type * @param string $valueType RETURNED: valuetype type * @return array|null */ protected function _getFieldValues(&$o, &$basetype, &$valueType) { $valueType = $o->attributes('valuetype'); $fieldValuesInDb = null; $this->registryEditVew->resolveXmlParamType($o); if ($o->attributes('base')) { $basetype = $o->attributes('base'); } else { $basetype = $o->attributes('type'); } switch ($o->attributes('type')) { case 'data': $data = $o->getElementByPath('data'); if ($data) { $dataTable = $data->attributes('table'); if (!$dataTable) { $dataTable = $this->table; } $xmlsql = new XmlQuery($this->_db, $dataTable, $this->_pluginParams); $xmlsql->process_orderby($data->getElementByPath('orderby')); // <data><orderby><field> fields $xmlsql->process_fields($data->getElementByPath('rows')); // <data><rows><field> fields $xmlsql->process_where($data->getElementByPath('where')); // <data><where><column> fields $groupby = $data->getElementByPath('groupby'); $xmlsql->process_groupby($groupby ? $groupby : 'value'); // <data><groupby><field> fields $fieldValuesInDb = $xmlsql->queryLoadObjectsList($data); // get the records // check for type="firstwords": $rows = $data->getElementByPath('rows'); /** @var $rows SimpleXMLElement|null */ if ($rows) { $textField = $rows->getChildByNameAttr('field', 'as', 'text'); /** @var $textField SimpleXMLElement|null */ if ($textField) { if ($textField->attributes('type') == 'firstwords') { $size = $textField->attributes('size'); if (!$size) { $size = 45; } foreach (array_keys($fieldValuesInDb) as $k) { $strippedContent = trim($fieldValuesInDb[$k]->text); if (cbIsoUtf_strlen($strippedContent) > $size) { $strippedContent = cbIsoUtf_substr($strippedContent, 0, $size) . '...'; } $fieldValuesInDb[$k]->text = $strippedContent; } } } } $data->addAttribute('dataprocessed', 'true'); } else { // echo 'filter type is data but no child data present !'; $fieldName = $o->attributes('name'); if ($o->attributes('value')) { $valueFieldName = $o->attributes('value'); } else { $valueFieldName = $fieldName; } $dataTable = $o->attributes('table'); if (!$dataTable) { $dataTable = $this->table; } $data = new SimpleXMLElement(<<<EOT <?xml version="1.0" encoding="UTF-8"?> <table table="{$dataTable}"> \t<rows> \t\t<field name="{$valueFieldName}" as="value" type="sql:field" /> \t\t<field name="{$fieldName}" as="text" type="sql:field" /> \t</rows> \t<orderby> \t\t<field name="{$fieldName}" ordering="ASC" /> \t</orderby> \t<groupby> \t\t<field name="{$fieldName}" /> \t</groupby> </table> EOT ); $xmlsql = new XmlQuery($this->_db, $dataTable, $this->_pluginParams); $xmlsql->process_orderby($data->getElementByPath('orderby')); // <data><orderby><field> fields $xmlsql->process_fields($data->getElementByPath('rows')); // <data><rows><field> fields $xmlsql->process_where($data->getElementByPath('where')); // <data><where><column> fields $groupby = $data->getElementByPath('groupby'); $xmlsql->process_groupby($groupby ? $groupby : 'value'); // <data><groupby><field> fields $fieldValuesInDb = $xmlsql->queryLoadObjectsList($data); // get the records } break; case 'field_show_only_if_selected': break; case 'list': case 'radio': case 'checkbox': case 'checkmark': case 'published': case 'usergroup': case 'viewaccesslevel': case 'tag': foreach ($o->children() as $option) { /** @var $option SimpleXMLElement */ if ($option->getName() == 'option') { $hasIndex = $option->attributes('index') !== '' && $option->attributes('index') !== null; $selObj = new \stdClass(); $selObj->value = $hasIndex ? $option->attributes('index') : $option->attributes('value'); if ($hasIndex) { $selObj->internalvalue = $option->attributes('value'); } $selObj->operator = $option->attributes('operator'); $selObj->text = $option->data(); $fieldValuesInDb[] = $selObj; } } break; case 'field': global $_CB_database; $where = array(); $where[] = "f." . $_CB_database->NameQuote('published') . " = 1"; $where[] = "f." . $_CB_database->NameQuote('name') . " != " . $_CB_database->Quote('NA'); $query = "SELECT f." . $_CB_database->NameQuote('fieldid') . " AS value" . ", f." . $_CB_database->NameQuote('name') . ' AS ' . $_CB_database->NameQuote('index') . ", f." . $_CB_database->NameQuote('title') . ' AS ' . $_CB_database->NameQuote('text') . ", f." . $_CB_database->NameQuote('table') . ' AS ' . $_CB_database->NameQuote('table') . ", " . $_CB_database->Quote('id') . ' AS ' . $_CB_database->NameQuote('table_key') . ", " . $_CB_database->Quote('=') . " AS operator" . "\n FROM " . $_CB_database->NameQuote('#__comprofiler_fields') . " AS f" . "\n LEFT JOIN " . $_CB_database->NameQuote('#__comprofiler_tabs') . " AS t" . " ON t." . $_CB_database->NameQuote('tabid') . " = f." . $_CB_database->NameQuote('tabid') . "\n WHERE " . implode("\n AND ", $where) . "\n ORDER BY t." . $_CB_database->NameQuote('position') . ", t." . $_CB_database->NameQuote('ordering') . ", f." . $_CB_database->NameQuote('ordering'); $_CB_database->setQuery($query); $fieldValuesInDb = $_CB_database->loadObjectList(); break; default: if (substr($o->attributes('type'), 0, 4) == 'sql:') { // get list for dropdown filter $fieldName = $o->attributes('name'); if ($o->attributes('value')) { $valueFieldName = $o->attributes('value'); } else { $valueFieldName = $fieldName; } $dataTable = $o->attributes('table'); if (!$dataTable) { $dataTable = $this->table; } $data = new SimpleXMLElement(<<<EOT <?xml version="1.0" encoding="UTF-8"?> <table table="{$dataTable}"> \t<rows> \t\t<field name="{$valueFieldName}" as="value" type="sql:field" /> \t\t<field name="{$fieldName}" as="text" type="sql:field" /> \t</rows> \t<orderby> \t\t<field name="{$fieldName}" ordering="ASC" /> \t</orderby> \t<groupby> \t\t<field name="{$fieldName}" /> \t</groupby> </table> EOT ); $xmlsql = new XmlQuery($this->_db, $dataTable, $this->_pluginParams); $xmlsql->process_orderby($data->getElementByPath('orderby')); // <data><orderby><field> fields $xmlsql->process_fields($data->getElementByPath('rows')); // <data><rows><field> fields $xmlsql->process_where($data->getElementByPath('where')); // <data><where><column> fields $groupby = $data->getElementByPath('groupby'); $xmlsql->process_groupby($groupby ? $groupby : 'value'); // <data><groupby><field> fields $fieldValuesInDb = $xmlsql->queryLoadObjectsList($data); // get the records $o->addAttribute('type', 'list'); /* $fieldName = $this->_db->getEscaped( $o->attributes( 'name' ) ); if ( $o->attributes( 'value' ) ) { $valueFieldName = $this->_db->getEscaped( $o->attributes( 'value' ) ); } else { $valueFieldName = $fieldName; } $tableName = $this->_db->getEscaped( $this->table ); $query = "SELECT `" . $valueFieldName . "` AS value, `" . $fieldName . "` AS text" . "\n FROM `" . $tableName . "`" . "\n GROUP BY " . $fieldName . "\n ORDER BY " . $fieldName ; $this->_db->setQuery( $query ); $fieldValuesInDb = $this->_db->loadObjectList(); */ } break; } return $fieldValuesInDb; }
/** * Loads the rows of menu * * @param SimpleXMLElement $child */ protected function _loadMenuRows(&$child) { if ($child->getName() == 'menu') { $listFieldsRows = $child->getElementByPath('fields'); $menuName = $child->attributes('name'); $this->rows[$menuName] = new Table(); if ($listFieldsRows) { foreach ($listFieldsRows->children() as $field) { /** @var $field SimpleXMLElement */ if ($field->attributes('type') == 'private') { $name = $field->attributes('name'); // $className = $field->attributes( 'class' ); // $methodName = $field->attributes( 'method' ); $value = $field->attributes('value'); $content = $value; // it will be called at rendering time: /* if ( $className && $methodName && class_exists( $className ) ) { $obj = new $className( $this->_db ); //TBD: implement the singleton similarly/calling _form_private if ( method_exists( $obj, $methodName ) ) { /* $row = $this->_modelOfData[0]; //TBD: checked.... foreach (get_object_vars($obj) as $key => $v) { if( substr( $key, 0, 1 ) != '_' ) { // internal attributes of an object are ignored if (isset($row->$key)) { $obj->$key = $row->$key; } } } * $content = $obj->$methodName( $value, $this->_pluginParams ); //TBD: pluginParams should be available by the method params() of $obj, not as function parameter } else { $content = 'Missing method ' . $methodName; } } else { $content = 'Missing class, or method in xml'; } */ $this->rows[$menuName]->{$name} = $content; } else { $xmlsql = new XmlQuery($this->_db, null, $this->_pluginParams); $xmlsql->process_field($field); $obj = null; if ($xmlsql->queryLoadObject($obj)) { // get the resulting object foreach (get_object_vars($obj) as $k => $v) { if (substr($k, 0, 1) != '_') { // internal attributes of an object are ignored $this->rows[$menuName]->{$k} = $v; } } // } else { // error in query... } } } } } }
/** * installs a field for plugin * * @param int $pluginId Id of the plugin creating the field * @param int $tabId Id of tab into which to install the field * @param SimpleXMLElement $field XML element of the field to install * @return int|false Field id or False on error */ function installField($pluginId, $tabId, $field) { global $_CB_database, $_PLUGINS; // Check to see if plugin tab already exists in db if (!$field->attributes('fieldid')) { $_CB_database->setQuery("SELECT fieldid FROM #__comprofiler_fields WHERE name = '" . $field->attributes('name') . "'"); $fieldid = $_CB_database->loadResult(); } else { $fieldid = $field->attributes('fieldid'); } $row = new FieldTable(); if ($fieldid) { $row->load((int) $fieldid); } $row->name = $field->attributes('name'); $row->pluginid = $pluginId; $row->tabid = $tabId; $row->type = $field->attributes('type'); $row->calculated = (int) $field->attributes('calculated'); if (!$row->fieldid) { $row->title = $field->attributes('title'); $row->description = trim($field->attributes('description')); $row->ordering = 99; $row->registration = $field->attributes('registration'); $row->profile = $field->attributes('profile'); $row->edit = $field->attributes('edit'); $row->readonly = $field->attributes('readonly'); $row->searchable = $field->attributes('searchable'); $row->params = $field->attributes('params'); } $dbTable = $field->getElementByPath('database/table'); if ($dbTable !== false) { $table = $dbTable->attributes('name'); } else { $table = $field->attributes('table'); } if ($table) { $row->table = $table; } else { $row->table = '#__comprofiler'; } // if the field type is unknown, suppose it's a field type of the plugin: $fieldTypePluginId = $_PLUGINS->getUserFieldPluginId($row->type); if (!$fieldTypePluginId) { // and register it so that the XML file for custom type can be found for store: $_PLUGINS->registerUserFieldTypes(array($row->type => 'CBfield_' . $row->type), $pluginId); } if (!$row->store()) { $this->setError(1, 'SQL error on field store2' . ': ' . $row->getError()); return false; } $fieldid = (int) $row->fieldid; return $fieldid; }