/** * Loads and parses the XML setup file * * @return boolean True on success, False on error */ function readInstallFile() { if ($this->installFilename() == '') { $this->setError(1, 'No filename specified'); return false; } if (file_exists($this->installFilename())) { $xmlString = trim(file_get_contents($this->installFilename())); $this->i_xmldocument = new SimpleXMLElement($xmlString); if (count($this->i_xmldocument->children()) == 0) { return false; } } $main_element = $this->i_xmldocument; // Check that it's am installation file if ($main_element->getName() != 'cbinstall') { $this->setError(1, 'File :"' . $this->installFilename() . '" is not a valid Joomla installation file'); return false; } $this->installType($main_element->attributes('type')); return true; }
/** * Converts a XML description of a SQL index into a full SQL type * * <index name="PRIMARY" type="primary"> * <column name="id" /> * </index> * <index name="rate_chars"> * <column name="rate" /> * <column name="_mychars" nametype="namesuffix" size="8" ordering="DESC" /> * </index> * <index name="myrate" type="unique" using="btree"> * <column name="rate" /> * </index> * * Returns: $fulltype: 'decimal(16,8) unsigned NULL DEFAULT NULL' * * @param SimpleXMLElement $index * @param string $colNamePrefix Prefix to add to all column names * @return string|boolean Full SQL creation type or NULL in case of no index/error */ protected function fullIndexType(SimpleXMLElement $index, $colNamePrefix) { $sqlIndexText = null; if ($index->getName() == 'index') { // first collect all columns of this index: $indexColumns = array(); foreach ($index->children() as $column) { if ($column->getName() == 'column') { $colNamePrefixed = $this->prefixedName($column, $colNamePrefix); $indexColText = $this->_db->NameQuote($colNamePrefixed); if ($column->attributes('size')) { $indexColText .= ' (' . (int) $column->attributes('size') . ')'; } if ($column->attributes('ordering')) { $indexColText .= ' ' . $this->_db->getEscaped($column->attributes('ordering')); } $indexColumns[] = $indexColText; } } if (count($indexColumns) > 0) { // then build the index creation SQL: if ($index->attributes('type')) { // PRIMARY, UNIQUE, FULLTEXT, SPATIAL: $sqlIndexText .= $this->_db->getEscaped(strtoupper($index->attributes('type'))) . ' '; } $sqlIndexText .= 'KEY '; if ($index->attributes('type') !== 'primary') { $sqlIndexText .= $this->_db->NameQuote($this->prefixedName($index, $colNamePrefix)) . ' '; } if ($index->attributes('using')) { // BTREE, HASH, RTREE: $sqlIndexText .= 'USING ' . $this->_db->getEscaped($index->attributes('using')) . ' '; } $sqlIndexText .= '(' . implode(', ', $indexColumns) . ')'; } } return $sqlIndexText; }
/** * Transforms XML to Array * @param SimpleXMLElement $el * @param string $callBacks * @return array */ protected function & xml2arr( &$el, &$callBacks ) { $names_values = array(); if ( $el ) { $nam = $el->getName(); if ( array_key_exists( $nam, $callBacks ) ) { $names_values[$nam] = call_user_func_array( $callBacks[$nam], array( &$el, &$callBacks ) ); } else { $names_values[$nam] = $el->attributes(); foreach ( $el->children() as $elChild ) { $names_values = array_merge_recursive( $names_values, array( $nam => $this->xml2arr( $elChild, $callBacks ) ) ); } } } return $names_values; }
/** * Draws a list of a SQL table * * @param string $viewType ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) * @return string HTML of table */ public function draw($viewType = 'view') { global $_CB_Backend_Menu; if (!$this->name) { $this->parseXML(); // get List scheme } $this->loadFilters(); $this->loadBatchProcess(); $this->_getTableState(); $this->_performTableActions(); if ($this->limit < 1) { $this->limit = 10; } if (!$this->rows) { $this->loadRows(); // get List content } $controller = new DrawController($this->input, $this->_tableBrowserModel, $this->_actions, $this->_options); $controller->setControl_name($this->name); if ($this->listFieldsRows) { $controller->createPageNvigator($this->total, $this->limitstart, $this->limit, $this->limits); } $controller->setFilters($this->_filterPossibilitesArray); $controller->setSearch($this->search, $this->quicksearchfields && count($this->quicksearchfields->children()) > 0); $controller->setOrderBy($this->orderby); $controller->setBatchProcess($this->_batchPossibilitesArray); $controller->setStatistics($this->_statisticsToDisplay); if ($this->toolbarmenu && count($this->toolbarmenu->children()) > 0) { $toolBarMenu = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><cbxml></cbxml>'); foreach ($this->toolbarmenu->children() as $menu) { $menuLink = $menu->attributes('link'); $menuAccess = true; $link = null; if ($menuLink) { $data = null; $link = $controller->drawUrl($menuLink, $menu, $data, null); if (!$link) { $menuAccess = false; } } if ($menuAccess) { /** @var $menu SimpleXMLElement */ $child = $toolBarMenu->addChildWithAttr('menu', null, null, $menu->attributes()); if ($link) { $child->addAttribute('urllink', $link); } } } $_CB_Backend_Menu->menuItems[] = $toolBarMenu; } ob_start(); $this->renderList($this->_tableBrowserModel, $this->rows, $controller, $this->_options, $viewType); $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Renders as ECHO HTML code * * @param SimpleXMLElement $modelView * @param array $modelRows * @param DrawController $controllerView * @param array $options * @return void */ protected function renderMenuGroup(&$modelView, &$modelRows, &$controllerView, $options) { global $_PLUGINS; $htmlFormatting = 'span'; if (count($this->_controllerModel->children()) > 0) { //TBD: not needed yet, but kept if needed $this->_applyStylingToMeAndChildren( $this->_controllerModel, $this->styling ); echo $this->renderMenuGroupHeader($this->_controllerModel, $htmlFormatting); foreach ($this->_controllerModel->children() as $child) { /** @var $child SimpleXMLElement */ // Check if ACL authorizes to view and to use that menu: if (!Access::authorised($child)) { continue; } if ($child->getName() == 'menu') { // Check if ACL authorizes to use the action linked by that menu: if (!$this->authorised($child)) { continue; } $menuName = $child->attributes('name'); echo $this->renderMenu($child, $modelRows[$menuName], $controllerView, $options, $htmlFormatting); } elseif ($child->getName() == 'showview') { $showviewType = $child->attributes('type'); if ($showviewType == 'plugins') { $groups = explode(',', $child->attributes('groups')); $action = $child->attributes('action'); $path = $child->attributes('path'); foreach ($groups as $group) { $matches = null; if (preg_match('/^([^\\[]+)\\[(.+)\\]$/', $group, $matches)) { $classId = $matches[2]; $group = $matches[1]; } else { $classId = null; } $_PLUGINS->loadPluginGroup($group, $classId, 0); $loadedPlugins = $_PLUGINS->getLoadedPluginGroup($group); foreach ($loadedPlugins as $plugin) { $element = $_PLUGINS->loadPluginXML('action', $action, $plugin->id); $viewModel = $element->getElementByPath($path); if ($viewModel) { foreach ($viewModel->children() as $extChild) { /** @var $extChild SimpleXMLElement */ if ($extChild->getName() == 'menu') { // Check if ACL authorizes to use the action linked by that menu: if (!$this->authorised($extChild)) { continue; } $menuName = $extChild->attributes('name'); echo $this->renderMenu($extChild, $modelRows[$menuName], $controllerView, $options, $htmlFormatting); } } } } } } elseif ($showviewType == 'xml') { // e.g.: <showview name="gateway_paymentstatus_information" mode="view" type="xml" file="processors/{payment_method}/edit.gateway" path="/*/views/view[@name="paymentstatusinformation"]" mandatory="false" /> $fromNode = $child->attributes('path'); $fromFile = $child->attributes('file'); $mandatory = $child->attributes('mandatory'); if ($fromNode && $fromFile !== null) { // $this->substituteName( $fromFile, true ); // $this->substituteName( $fromNode, false ); if ($fromFile !== '') { $fromFile = RegistryEditView::pathFromXML($fromFile . '.xml', $child, $this->_pluginObject); } if (strpos($fromFile, '/*/') !== false) { $parts = explode('/*/', $fromFile); $fromFiles = cbReadDirectory($parts[0], '.', false, true); // '^' . preg_quote( $subparts[0], '/' ) . '$' } else { $parts = null; $fromFiles = array($fromFile); } foreach ($fromFiles as $fromDirOrFile) { $viewModel = null; if ($fromDirOrFile === '') { $viewModel = $this->_views->xpath($fromNode); } else { if (!isset($parts) || is_dir($fromDirOrFile)) { $fromDirOrFile = $fromDirOrFile . (isset($parts[1]) ? '/' . $parts[1] : ''); if (file_exists($fromDirOrFile)) { $fromRoot = new SimpleXMLElement($fromDirOrFile, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0), true); $viewModel = $fromRoot->xpath($fromNode); } } else { continue; } } if ($viewModel && count($viewModel)) { foreach ($viewModel[0]->children() as $extChild) { /** @var $extChild SimpleXMLElement */ if ($extChild->getName() == 'menu') { // Check if ACL authorizes to use the action linked by that menu: if (!$this->authorised($extChild)) { continue; } $menuName = $extChild->attributes('name'); echo $this->renderMenu($extChild, $modelRows[$menuName], $controllerView, $options, $htmlFormatting); } } } elseif ($mandatory == 'false') { continue; } else { trigger_error('MenuController:showview: View file ' . $fromDirOrFile . ', path: ' . $fromNode . ' does not exist or is empty.', E_USER_NOTICE); } } } } } } echo $this->renderMenuGroupFooter($this->_controllerModel, $htmlFormatting); } }
/** * Deletes <files> * * @param SimpleXMLElement $files_element * @param cbAdminFileSystem $adminFS * @param string|null $installFileName * @return void */ protected function deleteFiles(SimpleXMLElement $files_element, cbAdminFileSystem $adminFS, $installFileName) { foreach ($files_element->children() as $file) { // delete the files $filename = $file->data(); if ($adminFS->file_exists($this->i_elementdir . $filename)) { $parts = pathinfo($filename); $subpath = $parts['dirname']; if ($subpath != '' && $subpath != '.' && $subpath != '..') { $adminFS->deldir(_cbPathName($this->i_elementdir . $subpath . '/')); } else { if ($file->getName() == 'foldername') { $adminFS->deldir(_cbPathName($this->i_elementdir . $filename . '/')); } elseif ($installFileName != $filename) { $adminFS->unlink(_cbPathName($this->i_elementdir . $filename, false)); } } } } }