/** * Returns full label of the type of the field (backend use only!) * * @return string plugin name: label (found in xml file) */ public function getFieldsParamsLabel() { global $_PLUGINS; $plugin = $_PLUGINS->getPluginObject($this->_pluginid); if ($this->_fieldXml) { return $plugin->name . ': ' . $this->_fieldXml->attributes('label'); } return $plugin->name . ': ' . "specific field-parameters"; }
/** * 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; }
/** * 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; }
/** * Checks authorization to perform an action: <action permission="core.edit or core.edit.own and core.manage" (and has prio over or) * * @param SimpleXMLElement $action * @return boolean * @throws \InvalidArgumentException */ public static function authorised($action) { $permission = $action->attributes('permission'); if ($permission === null) { return true; } $assetname = $action->attributes('permissionasset'); if (!$assetname) { $parent = $action->xpath('ancestor::*[@permissionasset]'); if ($parent) { $assetname = $parent[0]->attributes('permissionasset'); } } if (!$assetname) { trigger_error(CBTxt::T('TAG_NAME_MISSING_ASSET_NAME', '[tag] [name] missing asset name', array('[tag]' => $action->getName(), '[name]' => $action->attributes('name')))); $assetName = 'com_cbsubs'; // CBSubs GPL 3.0.0 is the only ones that will ever need that ! } /// $me = CBuser::getMyInstance(); $ors = explode(' or ', $permission); foreach ($ors as $or) { $ands = explode(' and ', $or); $stillOk = true; foreach ($ands as $perm) { /// if ( ! $me->authoriseAction( trim( $perm ), $assetname ) ) { if (!static::authoriseAction(trim($perm), $assetname)) { $stillOk = false; break; } } if ($stillOk) { return true; } } return false; }
/** * Checks if all columns of a xml description of all tables of a database matches the database * * Warning: removes columns tables and columns which would be added by the changes to XML !!! * * @param SimpleXMLElement $table * @param string $colNamePrefix Prefix to add to all column names * @param string $change 'drop': uninstalls columns/tables * @param boolean|null $strictlyColumns FALSE: allow for other columns, TRUE: doesn't allow for other columns, NULL: checks for attribute 'strict' in table * @return boolean TRUE: matches, FALSE: don't match */ protected function dropXmlTableDescription(SimpleXMLElement $table, $colNamePrefix = '', $change = 'drop', $strictlyColumns = false) { $isMatching = false; if ($change == 'drop' && $table->getName() == 'table') { $tableName = $this->prefixedName($table, $colNamePrefix); $columns = $table->getElementByPath('columns'); if ($tableName && $columns !== false) { if ($strictlyColumns === null) { $strictlyColumns = $table->attributes('strict') === 'true'; } $neverDropTable = $table->attributes('drop') === 'never'; $isMatching = true; $allColumns = $this->getAllTableColumns($tableName); if ($allColumns === false) { // table doesn't exist: do nothing } else { if ($strictlyColumns && !$neverDropTable) { if (in_array($tableName, array('#__comprofiler', '#_users', '#__comprofiler_fields'))) { // Safeguard against fatal error in XML file ! $errorMsg = sprintf('Fatal error: Trying to delete core CB table %s not allowed.', $tableName); echo $errorMsg; trigger_error($errorMsg, E_USER_ERROR); exit; } $this->dropTable($tableName); } else { // 1) Drop rows: $rows = $table->getElementByPath('rows'); if ($rows !== false) { $neverDropRows = $rows->attributes('drop') === 'never'; if (!$neverDropRows) { $strictRows = $rows->attributes('strict') === 'true'; foreach ($rows->children() as $row) { if ($row->getName() == 'row') { $neverDropRow = $row->attributes('drop') === 'never'; if ($strictRows && !$neverDropRow) { if (!$this->dropRow($tableName, $row, $colNamePrefix)) { $isMatching = false; } } } } } } // 2) Drop indexes: $indexes = $table->getElementByPath('indexes'); if ($indexes !== false) { $neverDropIndexes = $indexes->attributes('drop') === 'never'; if (!$neverDropIndexes) { $allIndexes = $this->getAllTableIndexes($tableName); foreach ($indexes->children() as $index) { if ($index->getName() == 'index') { $indexName = $this->prefixedName($index, $colNamePrefix); if ($indexName == 'PRIMARY') { $neverDropIndex = $index->attributes('drop') !== 'always'; } else { $neverDropIndex = $index->attributes('drop') === 'never'; } if (isset($allIndexes[$indexName]) && !$neverDropIndex) { if (!$this->dropIndex($tableName, $indexName)) { $isMatching = false; } } } } } } // 3) Drop columns: $neverDropColumns = $columns->attributes('drop') === 'never'; if (!$neverDropColumns) { foreach ($columns->children() as $column) { if ($column->getName() == 'column') { $neverDropColumn = $column->attributes('drop') === 'never'; $colNamePrefixed = $this->prefixedName($column, $colNamePrefix); if (isset($allColumns[$colNamePrefixed]) && !$neverDropColumn) { if (!$this->dropColumn($tableName, $colNamePrefixed)) { $isMatching = false; } } } } } } } } } return $isMatching; }
/** * 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; }
/** * Constructor * * @param InputInterface $input The Input * @param DatabaseDriverInterface $db The user form input * @param RegistryInterface $registry The string raw parms text * @param SimpleXMLElement $xmlElement The element in XML corresponding to the parameters * @param SimpleXMLElement $xml The root element * @param PluginTable $pluginObject The plugin object * @param int $tabId The tab id (if there is one) * @param string $maintagname The main name of the tag pf the file * @param string $attrname The attribute name to test for $attrvalue * @param string $attrvalue The attribute value to be tested */ function __construct(InputInterface $input, DatabaseDriverInterface $db, RegistryInterface $registry, SimpleXMLElement $xmlElement = null, SimpleXMLElement $xml = null, PluginTable $pluginObject = null, $tabId = null, $maintagname = 'cbinstall', $attrname = 'type', $attrvalue = 'plugin') { $this->input = $input; $this->_db = $db; $this->setRegistry($registry); $this->_xml = $xmlElement; if ($xml) { $this->_actions = $xml->getElementByPathOrNull('actions'); $this->_types = $xml->getElementByPathOrNull('types'); $this->_views = $xml->getElementByPathOrNull('views'); } $this->_pluginObject = $pluginObject; $this->_tabId = $tabId; $this->_maintagname = $maintagname; $this->_attrname = $attrname; $this->_attrvalue = $attrvalue; }
/** * 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; }
/** * Outputs legacy plugin views * * @deprecated 2.0 Use XML * * @param PluginTable $row * @param string $option * @param string $task * @param int $uid * @param string $action * @param SimpleXMLElement $element * @param string $mode * @param Registry $pluginParams * @return mixed|null */ public function editPluginView($row, $option, $task, $uid, $action, $element, $mode, $pluginParams) { global $_CB_framework, $_CB_database, $_PLUGINS; if (!$row->id) { $_CB_framework->enqueueMessage(CBTxt::T('Plugin id not found.'), 'error'); return null; } if (!$element) { $_CB_framework->enqueueMessage(CBTxt::T('No plugin XML found.'), 'error'); return null; } $adminHandlerModel = $element->getChildByNameAttr('handler', 'ui', 'admin'); if (!$adminHandlerModel || $row->element == 'cbpaidsubscriptions') { $adminActionsModel = $element->getChildByNameAttr('actions', 'ui', 'admin'); if ($adminActionsModel) { // New CB 2.0 method: $savedPluginId = $_PLUGINS->_loading; $_PLUGINS->_loading = (int) $row->id; /** @var ActionController $actionController */ /** @see CBLib\AhaWow\Controller\ActionController::__construct() */ $actionController = Application::DI()->get('CBLib\\AhaWow\\Controller\\ActionController'); $actionController->setData($row); $displayMode = $mode == 'applyPlugin' ? 'apply' : ($mode == 'savePlugin' ? 'save' : 'edit'); echo $actionController->drawView($option, null, $element, $displayMode); $_PLUGINS->_loading = $savedPluginId; return null; } else { return null; } } $class = $adminHandlerModel->attributes('class'); if ($class) { if (!class_exists($class)) { $_CB_framework->enqueueMessage(CBTxt::T('ADMIN_HANDLER_CLASS_CLASS_DOES_NOT_EXIST', 'Admin handler class [class] does not exist.', array('[class]' => $class)), 'error'); return null; } $handler = new $class($_CB_database); /** @var stdClass|CBController_plugin|cbpaidAdminView $handler */ return $handler->editPluginView($row, $option, $task, $uid, $action, $element, $mode, $pluginParams); } else { // new method in CB 1.2.3: $args = array(&$row, $option, $task, $uid, $action, &$element, $mode, &$pluginParams); return $_PLUGINS->call($row->id, 'editPluginView', 'get' . $row->element . 'Tab', $args, null, true); } }
/** * 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; }
/** * Writes the edit form for new and existing module * * A new record is defined when <var>$row</var> is passed with the <var>id</var> * property set to 0. * * @param array $options * @param array $actionPath * @param SimpleXMLElement $viewModel * @param TableInterface|\stdClass $data * @param RegistryEditController $params * @param PluginTable $pluginRow * @param string $viewType ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) * @param string $cbprevstate * @param boolean $htmlOutput True to output headers for CSS and Javascript */ public static function editPluginView($options, $actionPath, $viewModel, $data, $params, $pluginRow, $viewType, $cbprevstate, $htmlOutput) { global $_CB_framework, $_CB_Backend_Title, $_PLUGINS, $ueConfig; $name = $viewModel->attributes('name'); $label = $viewModel->attributes('label'); $iconPair = explode(':', $viewModel->attributes('icon')); if (count($iconPair) > 1) { $iconset = isset($iconPair[0]) ? $iconPair[0] : null; $icon = isset($iconPair[1]) ? $iconPair[1] : null; } else { $iconset = 'fa'; $icon = isset($iconPair[0]) ? $iconPair[0] : null; } if ($icon) { if ($iconset == 'fa') { $icon = 'fa fa-' . $icon; } elseif ($iconset) { $icon = $iconset . $icon; } } $id = null; if (is_object($data)) { $dataArray = get_object_vars($data); if (in_array('id', $dataArray)) { // General object $id = (int) $data->id; } elseif (in_array('tabid', $dataArray)) { // Field object $id = (int) $data->tabid; } elseif (in_array('fieldid', $dataArray)) { // Tab object $id = (int) $data->fieldid; } } if ($id !== null) { if (isset($data->title)) { $item = $data->title; } elseif (isset($data->name)) { $item = $data->name; } else { $item = $id; } $title = ($id ? CBTxt::T('Edit') : CBTxt::T('New')) . ($label ? ' ' . htmlspecialchars(CBTxt::T($label)) . ' ' : null) . ($item ? ' [' . htmlspecialchars(CBTxt::T($item)) . ']' : null); } else { $title = $label ? htmlspecialchars(CBTxt::T($label)) : null; } if ($viewModel->attributes('label')) { $showDisclaimer = true; if ($pluginRow) { if (!$icon) { $icon = 'cb-' . str_replace('.', '_', $pluginRow->element) . '-' . $name; } $_CB_Backend_Title = array(0 => array($icon, htmlspecialchars(CBTxt::T($pluginRow->name)) . ($title ? ': ' . $title : null))); } else { if (!$icon) { $icon = 'cb-' . $name; } $_CB_Backend_Title = array(0 => array($icon, htmlspecialchars(CBTxt::T('Community Builder')) . ($title ? ': ' . $title : null))); } // Null the label so the view form doesn't output it as we already did as page title: $viewModel->addAttribute('label', null); } else { $showDisclaimer = false; } $htmlFormatting = $viewModel->attributes('viewformatting'); if (!$htmlFormatting) { if ($_CB_framework->getUi() == 1 && (isset($ueConfig['use_divs']) && $ueConfig['use_divs'] == 1)) { $htmlFormatting = 'div'; } else { $htmlFormatting = 'table'; } } new cbTabs(true, 2); $settingsHtml = $params->draw(null, null, null, null, null, null, false, $viewType, $htmlFormatting); if ($htmlOutput) { outputCbTemplate(); outputCbJs(); self::outputAdminJs(); initToolTip(); self::outputRegTemplate(); } $return = null; if ($pluginRow && $pluginRow->id) { if (!$pluginRow->published) { $return .= '<div class="alert alert-danger">' . CBTxt::T('PLUGIN_NAME_IS_NOT_PUBLISHED', '[plugin_name] is not published.', array('[plugin_name]' => htmlspecialchars(CBTxt::T($pluginRow->name)))) . '</div>'; } if (!$_PLUGINS->checkPluginCompatibility($pluginRow)) { $return .= '<div class="alert alert-danger">' . CBTxt::T('PLUGIN_NAME_IS_NOT_COMPATIBLE_WITH_YOUR_CURRENT_CB_VERSION', '[plugin_name] is not compatible with your current CB version.', array('[plugin_name]' => htmlspecialchars(CBTxt::T($pluginRow->name)))) . '</div>'; } } if (is_object($data) && isset($data->id) && $data->id) { if (isset($data->published) && !$data->published) { $return .= '<div class="alert alert-danger">' . CBTxt::T('NAME_IS_NOT_PUBLISHED', '[name] is not published.', array('[name]' => htmlspecialchars(CBTxt::T($label)))) . '</div>'; } if (isset($data->enabled) && !$data->enabled) { $return .= '<div class="alert alert-danger">' . CBTxt::T('NAME_IS_NOT_ENABLED', '[name] is not enabled.', array('[name]' => htmlspecialchars(CBTxt::T($label)))) . '</div>'; } } if ($viewModel->attributes('formformatting') == 'none') { $return .= $settingsHtml ? $settingsHtml : null; } else { cbValidator::loadValidation(); $cssClass = RegistryEditView::buildClasses($viewModel); if (!$cssClass) { $cssClass = 'cb_form form-auto'; } $return .= '<form enctype="multipart/form-data" action="' . $_CB_framework->backendUrl('index.php') . '" method="post" name="adminForm" class="cbValidation ' . htmlspecialchars($cssClass) . '" id="cbAdminFormForm">' . ($settingsHtml ? $settingsHtml : null) . '<input type="hidden" name="option" value="' . htmlspecialchars($options['option']) . '" />' . ($pluginRow ? '<input type="hidden" name="cid" value="' . (int) $pluginRow->id . '" />' : null) . ($cbprevstate ? '<input type="hidden" name="cbprevstate" value="' . htmlspecialchars($cbprevstate) . '" />' : null); if ($actionPath) { foreach ($actionPath as $k => $v) { $return .= '<input type="hidden" name="' . htmlspecialchars($k) . '" value="' . htmlspecialchars($v) . '" />'; } } $return .= cbGetSpoofInputTag('plugin') . '</form>'; } if ($showDisclaimer) { $disclaimerTitle = 'Disclaimer'; $disclaimerText = 'This software comes "as is" with no guarantee for accuracy, function or fitness for any purpose.'; $disclaimerTitleTr = CBTxt::Th('Disclaimer'); $disclaimerTextTr = CBTxt::Th('This software comes "as is" with no guarantee for accuracy, function or fitness for any purpose.'); $return .= '<div class="cbregCopyrightfooter content-spacer" style="font-size:11px; color:black; display:block;">' . CBTxt::Th('CB_FOOTNOTE_OPEN_SOURCE_WITH_PLUGINS', 'Community Builder for Joomla, an open-source social framework by <a href="http://www.joomlapolis.com/?pk_campaign=in-cb&pk_kwd=footer" target="_blank">Joomlapolis.com</a>, easy to extend with <a href="http://www.joomlapolis.com/cb-solutions?pk_campaign=in-cb&pk_kwd=footer" target="_blank">CB plugins</a>. Professional <a href="http://www.joomlapolis.com/support?pk_campaign=in-cb&pk_kwd=footer" target="_blank">Support</a> is available with a <a href="http://www.joomlapolis.com/memberships?pk_campaign=in-cb&pk_kwd=footer" target="_blank">Membership</a>.') . '<br /><strong>' . $disclaimerTitle . ':</strong> ' . $disclaimerText . ($disclaimerText != $disclaimerTextTr ? '<br /><strong>' . $disclaimerTitleTr . ':</strong> ' . $disclaimerTextTr : null) . '<br />' . CBTxt::Th('CB_FOOTNOTE_REVIEW_AND_RATE_AT_JED', 'If you use Community Builder, please post a rating and a review on the <a href="[JEDURL]" target="_blank">Joomla! Extensions Directory</a>.', array('[JEDURL]' => htmlspecialchars('http://extensions.joomla.org/extensions/clients-a-communities/communities/210 '))) . '</div>'; } echo $return; }
/** * Renders the header of the menu group * * @param SimpleXMLElement $param * @param string $htmlFormatting * @return string */ protected function renderMenuGroupHeader(&$param, $htmlFormatting) { $html = array(); $legend = $param->attributes('label'); $description = $param->attributes('description'); $cssclass = RegistryEditView::buildClasses($param); if ($htmlFormatting == 'table') { $html[] = '<tr><td colspan="3" style="width: 100%;"' . ($cssclass ? ' class="' . htmlspecialchars($cssclass) . '"' : '') . '>'; } elseif ($htmlFormatting == 'td') { $html[] = '<td' . ($cssclass ? ' class="' . htmlspecialchars($cssclass) . '"' : '') . '>'; } if ($legend) { $html[] = '<h2>' . CBTxt::Th($legend) . '</h2>'; } if ($htmlFormatting == 'table') { $html[] = '<table class="table table-noborder">'; if ($description) { $html[] = '<tr><td colspan="3" style="width: 100%;"><strong>' . CBTxt::Th($description) . '</strong></td></tr>'; } } elseif ($htmlFormatting == 'td') { if ($description) { $html[] = '<td colspan="3" style="width: 100%;"><strong>' . CBTxt::Th($description) . '</strong></td>'; } } else { if ($description) { $html[] = '<strong>' . CBTxt::Th($description) . '</strong>'; } } if (!in_array($htmlFormatting, array('table', 'td'))) { $html[] = '<div class="cbButtonMenu' . ($cssclass ? ' ' . htmlspecialchars($cssclass) : '') . '">'; } return implode('', $html); }
/** * Extends the XML invoice address in params * * @param SimpleXMLElement $param * @param PluginTable $pluginObject * @param cbpaidPaymentBasket $paymentBasket (the data being displayed) * @param boolean $isSaving * @return SimpleXMLElement */ public function onxmlBeforeCbSubsDisplayOrSaveInvoice( /** @noinspection PhpUnusedParameterInspection */ $param, $pluginObject, $paymentBasket, $isSaving ) { global $_CB_framework, $_PLUGINS; $paymentItems = $paymentBasket->loadPaymentItems(); $taxableTotalizers = $paymentBasket->loadPaymentTotalizers(); $_PLUGINS->loadPluginGroup( 'user/plug_cbpaidsubscriptions/plugin/cbsubstax/validations', null, ( $_CB_framework->getUi() == 2 ? 0 : 1 ) ); $taxRulesRates = cbpaidPaymentTotalizer_salestax::getApplicableRatesWithoutBusinessCheck( $paymentBasket, $paymentItems, $taxableTotalizers ); $fromXml = array(); foreach ( $taxRulesRates as $AllTaxRates ) { foreach ( $AllTaxRates as $taxRate ) { //$taxRate = NEW cbpaidsalestaxTotalizertype(); $business_check = $taxRate->business_check; if ( $business_check ) { $absoluteValidationsPath = $_CB_framework->getCfg('absolute_path') . '/'. $_PLUGINS->getPluginRelPath( $pluginObject ) . '/plugin/cbsubstax/validations/' . $business_check; $valphp = $absoluteValidationsPath . '/validation.php'; if ( is_readable( $valphp ) ) { /** @noinspection PhpIncludeInspection */ include_once $valphp; // $className = 'cbpaidValidate_' . $tax->business_check; } $fromFile = $absoluteValidationsPath . '/xml/edit.invoice.xml'; if ( is_readable( $fromFile ) ) { $fromRoot = new SimpleXMLElement( $fromFile, LIBXML_NONET | ( defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0 ), true ); $fromXml = array_merge( $fromXml, $fromRoot->xpath( '/*/editinvoicevalidationintegration/*' ) ); } } } } return $fromXml; }
/** * 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)); } } } } }
function cbInstaller_install_plugins(&$return) { global $_CB_framework, $_CB_adminpath, $ueConfig; cbimport('cb.adminfilesystem'); cbimport('cb.installer'); $cbDatabase = \CBLib\Application\Application::Database(); // List of core plugins that are no longer core, but we just want to disable core status and not remove as they don't conflict: $deprecated = array('bootstrap', 'winclassic', 'webfx', 'osx', 'luna', 'dark', 'yanc', 'cb.mamblogtab', 'cb.simpleboardtab', 'cb.authortab'); foreach ($deprecated as $pluginElement) { $plugin = new PluginTable(); if ($plugin->load(array('element' => $pluginElement))) { $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('iscore') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('id') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_tabs') . "\n SET " . $cbDatabase->NameQuote('sys') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('pluginid') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] tabs failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n SET " . $cbDatabase->NameQuote('sys') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('pluginid') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] fields failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } } } // List of plugins that conflict with the core that need to be removed (normally due to being merged into core): $conflicted = array('bootstrap', 'winclassic', 'webfx', 'osx', 'luna', 'dark', 'yanc', 'cb.mamblogtab', 'cb.authortab', 'cbvideofield', 'cb.filefield'); foreach ($conflicted as $pluginElement) { $plugin = new PluginTable(); if ($plugin->load(array('element' => $pluginElement))) { if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } } // Ensure Default template, CB Core, and language plugins are published as they are not allowed to be unpublished: $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('published') . " = 1" . "\n WHERE ( " . $cbDatabase->NameQuote('id') . " IN " . $cbDatabase->safeArrayOfIntegers(array(1, 7)) . ' OR ' . $cbDatabase->NameQuote('type') . ' = ' . $cbDatabase->quote('language') . ' )'; $cbDatabase->setQuery($query); $cbDatabase->query(); $pluginsFile = $_CB_adminpath . 'pluginsfiles.tgz'; // We need to ensure the core plugins archive actually exists before doing anything with it: if (!file_exists($pluginsFile)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins archive [path] missing.', array('[path]' => $pluginsFile)) . '</div>'; return false; } // We need zlib to unzip packages so lets check that it exists: if (!extension_loaded('zlib')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::T('Core plugins can not be installed as zlib is not installed.') . '</div>'; return false; } $installer = new cbInstallerPlugin(); // Uncompress the core plugins so we can install them: if (!$installer->upload($pluginsFile, true, false)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins can not be installed as uncompressing [path] failed.', array('[path]' => $pluginsFile)) . '</div>'; return false; } $adminFS = cbAdminFileSystem::getInstance(); $baseDir = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler'; // Create the base plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin')) { if (!$adminFS->mkdir($baseDir . '/plugin')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/index.html')) . '</div>'; return false; } } // Create the language template directory: if (!$adminFS->is_dir($baseDir . '/plugin/language')) { if (!$adminFS->mkdir($baseDir . '/plugin/language')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/language')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/language/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/language/index.html')) . '</div>'; return false; } } // Create the template plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin/templates')) { if (!$adminFS->mkdir($baseDir . '/plugin/templates')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/templates')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/templates/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/templates/index.html')) . '</div>'; return false; } } // Create the user plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin/user')) { if (!$adminFS->mkdir($baseDir . '/plugin/user')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/user')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/user/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/user/index.html')) . '</div>'; return false; } } // Install core plugins 1 by 1 silently: $installFrom = $installer->installDir(); $filesList = cbReadDirectory($installFrom, '.', true); foreach ($filesList as $file) { if (preg_match('/^.+\\.xml$/i', $file)) { $plgPath = $installFrom . (substr($installFrom, -1, 1) == '/' ? '' : '/') . $file; $plgXml = new SimpleXMLElement(trim(file_get_contents($plgPath))); if ($plgXml->getName() == 'cbinstall') { $plgDir = dirname($plgPath) . '/'; ob_start(); $plgInstaller = new cbInstallerPlugin(); $installed = $plgInstaller->install($plgDir); ob_end_clean(); if (!$installed) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Installing core plugin [plugin] failed with error [error].', array('[plugin]' => $plgInstaller->i_elementname ? $plgInstaller->i_elementname : $file, '[error]' => $plgInstaller->getError())) . '</div>'; return false; } } } } // Delete the expanded core plugins archive: $result = $adminFS->deldir(_cbPathName($installFrom . '/')); if ($result === false) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::T('Deleting expanded core plugins archive failed.') . '</div>'; } // Delete the core plugins archive: $result = $adminFS->unlink(_cbPathName($pluginsFile, false)); if ($result === false) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Deleting core plugins archive [path] failed.', array('[path]' => $pluginsFile)) . '</div>'; } // Sets the as ready so config can actually load this time: \CB\Application\CBConfig::setCbConfigReadyToLoad(true); // Load the config now that the tables exist encase they didn't during install: \CB\Application\CBConfig::loadLegacyCBueConfig(); // Migrate old file based configuration to database based configuration: $newConfig = null; if ($adminFS->file_exists($_CB_adminpath . 'ue_config.php')) { /** @noinspection PhpIncludeInspection */ include_once $_CB_adminpath . 'ue_config.php'; // Reset the template back to default if upgrading from a 1.x install: $ueConfig['templatedir'] = 'default'; $newConfig = json_encode($ueConfig); } // Convert CB 1.x nesttabs into new nested tab display mode if needed: if (isset($ueConfig['nesttabs'])) { // Update all the tabs that would have normally auto-nested and make them nested displays $query = 'UPDATE ' . $cbDatabase->NameQuote('#__comprofiler_tabs') . "\n SET " . $cbDatabase->NameQuote('displaytype') . " = " . $cbDatabase->Quote('nested') . "\n WHERE " . $cbDatabase->NameQuote('displaytype') . " = " . $cbDatabase->Quote('tab') . "\n AND " . $cbDatabase->NameQuote('fields') . " = 1" . "\n AND ( ( " . $cbDatabase->NameQuote('pluginclass') . " IS NULL )" . ' OR ( ' . $cbDatabase->NameQuote('sys') . ' = 2 ) )'; $cbDatabase->setQuery($query); $cbDatabase->query(); unset($ueConfig['nesttabs']); $newConfig = json_encode($ueConfig); } // Migrate global avatar params to field params: if (isset($ueConfig['allowAvatar']) || isset($ueConfig['defaultAvatar']) || isset($ueConfig['defaultPendingAvatar']) || isset($ueConfig['allowAvatarGallery'])) { $field = new FieldTable(); if ($field->load(array('name' => 'avatar'))) { $fieldParams = new Registry($field->params); if (isset($ueConfig['allowAvatar'])) { $fieldParams->set('image_allow_uploads', (int) $ueConfig['allowAvatar']); unset($ueConfig['allowAvatar']); } if (isset($ueConfig['defaultAvatar'])) { $fieldParams->set('defaultAvatar', $ueConfig['defaultAvatar']); unset($ueConfig['defaultAvatar']); } if (isset($ueConfig['defaultPendingAvatar'])) { $fieldParams->set('defaultPendingAvatar', $ueConfig['defaultPendingAvatar']); unset($ueConfig['defaultPendingAvatar']); } if (isset($ueConfig['allowAvatarGallery'])) { $fieldParams->set('image_allow_gallery', (int) $ueConfig['allowAvatarGallery']); unset($ueConfig['allowAvatarGallery']); } $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } $newConfig = json_encode($ueConfig); } // Migrate global email ajax checker to field specific param: if (isset($ueConfig['reg_email_checker'])) { $field = new FieldTable(); if ($field->load(array('name' => 'email'))) { $fieldParams = new Registry($field->params); $fieldParams->set('field_check_email', (string) $ueConfig['reg_email_checker']); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } unset($ueConfig['reg_email_checker']); $newConfig = json_encode($ueConfig); } // Migrate global image params to field params: if (isset($ueConfig['allowAvatarUpload'])) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('name') . " != " . $cbDatabase->Quote('avatar') . "\n AND " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('image'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('image_allow_uploads', (int) $ueConfig['allowAvatarUpload']); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } unset($ueConfig['allowAvatarUpload']); $newConfig = json_encode($ueConfig); } // Convert CB 1.x allow_profileviewbyGID into new profile_viewaccesslevel if needed: if (isset($ueConfig['allow_profileviewbyGID']) && !isset($ueConfig['profile_viewaccesslevel'])) { $ueConfig['profile_viewaccesslevel'] = \CBLib\Application\Application::CmsPermissions()->convertOldGroupToViewAccessLevel($ueConfig['allow_profileviewbyGID'], 'CB Profiles access'); unset($ueConfig['allow_profileviewbyGID']); $newConfig = json_encode($ueConfig); } // Convert CB 1.x allow_profileviewbyGID into new profile_viewaccesslevel if needed: if (isset($ueConfig['imageApproverGid']) && !isset($ueConfig['moderator_viewaccesslevel'])) { $ueConfig['moderator_viewaccesslevel'] = \CBLib\Application\Application::CmsPermissions()->convertOldGroupToViewAccessLevel($ueConfig['imageApproverGid'], 'CB Moderators access'); unset($ueConfig['imageApproverGid']); $newConfig = json_encode($ueConfig); } // If old configuration for terms and conditions exists we need to pass it to the terms and conditions field: if (isset($ueConfig['reg_enable_toc']) && isset($ueConfig['reg_toc_url'])) { if ($ueConfig['reg_enable_toc'] == 1 && $ueConfig['reg_toc_url'] != '') { $field = new FieldTable(); if ($field->load(array('name' => 'acceptedterms'))) { $fieldParams = new Registry($field->params); if ($fieldParams->get('terms_url') == '') { $fieldParams->set('terms_url', $ueConfig['reg_toc_url']); $field->set('required', 1); $field->set('registration', 1); $field->set('edit', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } } } unset($ueConfig['reg_enable_toc']); unset($ueConfig['reg_toc_url']); $newConfig = json_encode($ueConfig); } // If old configuration for userlists exists we need to pass it to the userlist it self: if (isset($ueConfig['num_per_page']) && isset($ueConfig['allow_profilelink'])) { if ($ueConfig['num_per_page'] != '' || $ueConfig['allow_profilelink'] != 1) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_lists'); $cbDatabase->setQuery($query); $lists = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\ListTable', array($cbDatabase)); /** @var $lists ListTable[] */ foreach ($lists as $list) { $listParams = new Registry($list->params); $changed = false; if ($ueConfig['num_per_page'] != '' && $listParams->get('list_limit') == '') { $listParams->set('list_limit', $ueConfig['num_per_page']); $changed = true; } if ($ueConfig['allow_profilelink'] != 1 && $listParams->get('allow_profilelink') == '') { $listParams->set('allow_profilelink', $ueConfig['allow_profilelink']); $changed = true; } if ($changed) { $list->set('params', $listParams->asJson()); if (!$list->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Userlist [title] failed to migrate. Error: [error]', array('[name]' => $list->title, '[error]' => $list->getError())) . '</div>'; } } } } unset($ueConfig['num_per_page']); unset($ueConfig['allow_profilelink']); $newConfig = json_encode($ueConfig); } // Establish default for any missing config params: $configXml = new SimpleXMLElement(trim(file_get_contents($_CB_adminpath . 'xmlcb/views/view.com_comprofiler.editconfig.xml'))); if ($configXml) { $configXmlParams = $configXml->xpath('//param'); if ($configXmlParams) { $configXmlSet = false; foreach ($configXmlParams as $configXmlParam) { $k = (string) $configXmlParam->attributes('name'); if (!isset($ueConfig[$k])) { $v = (string) $configXmlParam->attributes('default'); if ($k) { $ueConfig[$k] = $v; $configXmlSet = true; } } } if ($configXmlSet) { $newConfig = json_encode($ueConfig); } } } // Update cb.core with the new cb config: if ($newConfig) { $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('params') . " = " . $cbDatabase->Quote($newConfig) . "\n WHERE " . $cbDatabase->NameQuote('id') . " = 1"; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $_CB_framework->enqueueMessage(CBTxt::P('Failed to update configuration params in database. Error: [error]', array('[error]' => $cbDatabase->getErrorMsg())), 'error'); return false; } } // Remove the old config file if it exists as we migrated above already: if ($adminFS->file_exists($_CB_adminpath . 'ue_config.php')) { $adminFS->unlink($_CB_adminpath . 'ue_config.php'); } // Migrate old userlist columns to new usage: $tableFields = $cbDatabase->getTableFields('#__comprofiler_lists'); if (isset($tableFields['#__comprofiler_lists'])) { $userListFields = array_keys($tableFields['#__comprofiler_lists']); $userListOldFields = array('useraccessgroupid', 'sortfields', 'filterfields', 'col1title', 'col1enabled', 'col1fields', 'col1captions', 'col2title', 'col2enabled', 'col2fields', 'col2captions', 'col3title', 'col3enabled', 'col3fields', 'col3captions', 'col4title', 'col4enabled', 'col4fields', 'col4captions'); // At least 1 legacy column still exists so lets begin migration of userlists: if (array_intersect($userListOldFields, $userListFields)) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_lists'); $cbDatabase->setQuery($query); $lists = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\ListTable', array($cbDatabase)); /** @var $lists ListTable[] */ foreach ($lists as $list) { $listParams = new Registry($list->params); $listSorting = array(); $listSortFields = $list->get('sortfields') ? explode(', ', str_replace('`', '', $list->get('sortfields'))) : array(); $paramsChanged = false; foreach ($listSortFields as $listSortField) { $sortParts = explode(' ', $listSortField); $sortField = isset($sortParts[0]) ? trim($sortParts[0]) : null; if ($sortField) { $sortDirection = isset($sortParts[1]) ? trim($sortParts[1]) : 'ASC'; $listSorting[] = array('column' => $sortField, 'direction' => $sortDirection); } } if ($listSorting) { $paramsChanged = true; $listParams->set('sort_mode', '0'); $listParams->set('basic_sort', $listSorting); } $listFilterFields = $list->get('filterfields'); if ($listFilterFields) { $filterType = substr($listFilterFields, 0, 1); $listFilterFields = rawurldecode(substr($listFilterFields, 2, -1)); if ($filterType == 'a') { $paramsChanged = true; $listParams->set('filter_mode', '1'); $listParams->set('filter_advanced', $listFilterFields); } else { $listFilters = array(); $basicFilters = explode(' AND ', $listFilterFields); foreach ($basicFilters as $basicFilter) { if (preg_match('/`(.+)`\\s*(.+)\\s*\'(.*)\'|`(.+)`\\s*(.+)/i', $basicFilter, $matches)) { $filterField = isset($filterParts[1]) ? $filterParts[1] : (isset($filterParts[4]) ? $filterParts[4] : null); $filterOperator = isset($filterParts[2]) ? $filterParts[2] : (isset($filterParts[5]) ? $filterParts[5] : null); $filterVal = isset($filterParts[3]) ? $filterParts[3] : ''; switch ($filterOperator) { case '!=': $filterOperator = '<>||ISNULL'; break; case 'IS NULL': case "= ''": $filterOperator = '='; $filterVal = ''; break; case 'IS NOT NULL': case "!= ''": $filterOperator = '!='; $filterVal = ''; break; } if ($filterField && $filterOperator) { $listFilters[] = array('column' => $filterField, 'operator' => $filterOperator, 'value' => $filterVal); } } } if ($listFilters) { $paramsChanged = true; $listParams->set('filter_mode', '0'); $listParams->set('filter_basic', $listFilters); } } } $listColumns = array(); for ($i = 1, $n = 4; $i <= $n; $i++) { if ($list->get('col' . $i . 'enabled')) { $columnTitle = $list->get('col' . $i . 'title', ''); $columnCaptions = (int) $list->get('col' . $i . 'captions', 0); $columnFields = $list->get('col' . $i . 'fields') ? explode('|*|', $list->get('col' . $i . 'fields')) : array(); $listFields = array(); foreach ($columnFields as $columnField) { $listFields[] = array('field' => (string) $columnField, 'display' => $columnCaptions ? '1' : '4'); } if ($listFields) { $listColumns[] = array('title' => $columnTitle, 'size' => '3', 'cssclass' => '', 'fields' => $listFields); } } } if ($listColumns) { $paramsChanged = true; $listParams->set('columns', $listColumns); } if ($paramsChanged || $list->get('usergroupids')) { $list->set('usergroupids', implode('|*|', explode(', ', $list->get('usergroupids')))); $list->set('params', $listParams->asJson()); if (!$list->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Userlist [title] failed to migrate. Error: [error]', array('[name]' => $list->title, '[error]' => $list->getError())) . '</div>'; } } } $userListDrop = array(); foreach ($userListOldFields as $userListOldField) { if (in_array($userListOldField, $userListFields)) { $userListDrop[] = $cbDatabase->NameQuote($userListOldField); } } if ($userListDrop) { $query = 'ALTER TABLE ' . $cbDatabase->NameQuote('#__comprofiler_lists') . "\n DROP " . implode(', DROP ', $userListDrop); $cbDatabase->setQuery($query); $cbDatabase->query(); } } } // Migrates password strength parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbpasswordstrength'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('password'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('passTestSrength', (string) $fieldParams->get('pswstr_display', 1)); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates ajax points field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbajaxpointsfield'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('ajaxpoints'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); switch ((int) $fieldParams->get('ajax_layout', 1)) { case 1: $fieldParams->set('points_layout', '[minus] [value] [plus]'); break; case 2: $fieldParams->set('points_layout', '[plus] [value] [minus]'); break; case 3: $fieldParams->set('points_layout', '[value] [minus][plus]'); break; case 4: $fieldParams->set('points_layout', '[value] [plus][minus]'); break; case 5: $fieldParams->set('points_layout', '[minus][plus] [value]'); break; case 6: $fieldParams->set('points_layout', '[plus][minus] [value]'); break; } $fieldParams->set('points_inc_plus', (string) $fieldParams->get('ajax_increment_up', 1)); $fieldParams->set('points_inc_minus', (string) $fieldParams->get('ajax_increment_down', 1)); $fieldParams->set('points_access', '8'); $fieldParams->set('points_access_custom', (string) $fieldParams->get('ajax_access', 0)); $field->set('type', 'points'); $field->set('pluginid', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates rating field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'ratingfield'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " IN " . $cbDatabase->safeArrayOfStrings(array('myrating', 'yourrating')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); if ($field->type == 'myrating') { $fieldParams->set('rating_access', '2'); } else { if ($fieldParams->get('AllowAnnonymous', 1)) { $fieldParams->set('rating_access', '3'); } else { $fieldParams->set('rating_access', '4'); $fieldParams->set('rating_access_exclude', '1'); } } $fieldParams->set('rating_number', (string) $fieldParams->get('NumStars', 5)); switch ((int) $fieldParams->get('RatingFraction', 1)) { case 1: $fieldParams->set('rating_step', '1'); break; case 2: $fieldParams->set('rating_step', '0.5'); break; case 3: $fieldParams->set('rating_step', '0.33'); break; case 4: $fieldParams->set('rating_step', '0.25'); break; } $field->set('type', 'rating'); $field->set('pluginid', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates verify email field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbverifyemail'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " IN " . $cbDatabase->safeArrayOfStrings(array('emailaddress', 'primaryemailaddress')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('fieldVerifyInput', $fieldParams->get('verifyemail_display_reg', 1) || $fieldParams->get('verifyemail_display_edit', 0) ? '1' : '0'); $fieldParams->set('verifyEmailTitle', $fieldParams->get('verifyemail_title', '_UE_VERIFY_SOMETHING')); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates forum integration parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cb.simpleboardtab'))) { $pluginParams = new Registry($plugin->params); $cbForums = new PluginTable(); if ($cbForums->load(array('element' => 'cbforums'))) { $cbForumsParams = new Registry($cbForums->params); if ((int) $pluginParams->get('forumType', 0) == 4) { $cbForumsParams->set('forum_model', '6'); } else { $cbForumsParams->set('forum_model', '1'); } switch ((int) $pluginParams->get('sidebarMode', 0)) { case 1: $cbForumsParams->set('k20_personaltext', $pluginParams->get('sidebarBeginner1')); $cbForumsParams->set('k20_gender', $pluginParams->get('sidebarBeginner4')); $cbForumsParams->set('k20_birthdate', $pluginParams->get('sidebarBeginner2')); $cbForumsParams->set('k20_location', $pluginParams->get('sidebarBeginner3')); $cbForumsParams->set('k20_icq', $pluginParams->get('sidebarBeginner5')); $cbForumsParams->set('k20_aim', $pluginParams->get('sidebarBeginner6')); $cbForumsParams->set('k20_yim', $pluginParams->get('sidebarBeginner7')); $cbForumsParams->set('k20_msn', $pluginParams->get('sidebarBeginner8')); $cbForumsParams->set('k20_skype', $pluginParams->get('sidebarBeginner9')); $cbForumsParams->set('k20_twitter', $pluginParams->get('sidebarBeginner12')); $cbForumsParams->set('k20_facebook', $pluginParams->get('sidebarBeginner13')); $cbForumsParams->set('k20_gtalk', $pluginParams->get('sidebarBeginner10')); $cbForumsParams->set('k20_myspace', $pluginParams->get('sidebarBeginner14')); $cbForumsParams->set('k20_linkedin', $pluginParams->get('sidebarBeginner15')); $cbForumsParams->set('k20_delicious', $pluginParams->get('sidebarBeginner16')); $cbForumsParams->set('k20_digg', $pluginParams->get('sidebarBeginner18')); $cbForumsParams->set('k20_blogspot', $pluginParams->get('sidebarBeginner19')); $cbForumsParams->set('k20_flickr', $pluginParams->get('sidebarBeginner20')); $cbForumsParams->set('k20_bebo', $pluginParams->get('sidebarBeginner21')); $cbForumsParams->set('k20_website', $pluginParams->get('sidebarBeginner11')); break; case 2: $cbForumsParams->set('k20_sidebar_reg', $pluginParams->get('sidebarAdvancedExists')); $cbForumsParams->set('k20_sidebar_anon', $pluginParams->get('sidebarAdvancedPublic')); $cbForumsParams->set('k20_sidebar_del', $pluginParams->get('sidebarAdvancedDeleted')); break; } $cbForums->set('params', $cbForumsParams->asJson()); if (!$cbForums->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] failed to migrate. Error: [error]', array('[element]' => $plugin->element, '[error]' => $cbForums->getError())) . '</div>'; } } // Migrate the forum fields to ensure their display mode is set: $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('name') . " IN " . $cbDatabase->safeArrayOfStrings(array('forumrank', 'forumposts', 'forumkarma')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); switch ($field->name) { case 'forumposts': $fieldParams->set('forumStatus', 'posts'); break; case 'forumkarma': $fieldParams->set('forumStatus', 'karma'); break; case 'forumrank': $fieldParams->set('forumStatus', 'rank'); break; } $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Removes legacy about cb menu items from CB Menu tab params $tab = new TabTable(); if ($tab->load(17)) { $tabParams = new Registry($tab->params); if ($tabParams->get('firstSubMenuName') == '_UE_MENU_ABOUT_CB') { $tabParams->set('firstSubMenuName', ''); $tabParams->set('firstSubMenuHref', ''); if ($tabParams->get('firstMenuName') == '_UE_MENU_CB' && !$tabParams->get('secondSubMenuName')) { $tabParams->set('firstMenuName', ''); } $tab->set('params', $tabParams->asJson()); if (!$tab->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Tab [title] failed to migrate. Error: [error]', array('[title]' => $tab->title, '[error]' => $tab->getError())) . '</div>'; } } } // We need to fix the name fields publish state: switch ($ueConfig['name_style']) { case 2: $nameArray = array('name' => 0, 'firstname' => 1, 'middlename' => 0, 'lastname' => 1); break; case 3: $nameArray = array('name' => 0, 'firstname' => 1, 'middlename' => 1, 'lastname' => 1); break; case 1: default: $nameArray = array('name' => 1, 'firstname' => 0, 'middlename' => 0, 'lastname' => 0); break; } foreach ($nameArray as $name => $published) { $query = 'UPDATE ' . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n SET " . $cbDatabase->NameQuote('published') . " = " . (int) $published . "\n WHERE " . $cbDatabase->NameQuote('name') . " = " . $cbDatabase->Quote($name); $cbDatabase->setQuery($query); $cbDatabase->query(); } return true; }
function finishInstallation($option) { global $_CB_framework, $ueConfig, $task; // Try extending time, as unziping/ftping took already quite some... : @set_time_limit(240); _CBsecureAboveForm('finishInstallation'); $tgzFile = $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/pluginsfiles.tgz'; $installerFile = $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/'; if (file_exists($installerFile . 'comprofiler.xml')) { $installerFile .= 'comprofiler.xml'; } elseif (file_exists($installerFile . 'comprofilej.xml')) { $installerFile .= 'comprofilej.xml'; } elseif (file_exists($installerFile . 'comprofileg.xml')) { $installerFile .= 'comprofileg.xml'; } if (!file_exists($tgzFile)) { echo CBTxt::T('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'); return; } $installer = new cbInstallerPlugin(); $client = 2; // Check that the zlib is available if (!extension_loaded('zlib')) { cbInstaller::renderInstallMessage(CBTxt::T('The installer cannot continue before zlib is installed'), CBTxt::T('Installer - Error'), $installer->returnTo($option, $task, $client)); return; } if (!$installer->upload($tgzFile, true, false)) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Uncompressing %s failed.'), $tgzFile), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } $adminFS = cbAdminFileSystem::getInstance(); $installFrom = $installer->installDir(); $filesList = cbReadDirectory($installFrom, '.', true); // check if core directories exist as are needed to install plugins: $baseDir = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler'; if (!$adminFS->is_dir($baseDir . '/plugin')) { if (!$adminFS->mkdir($baseDir . '/plugin')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create directory "%s"'), $baseDir . '/plugin'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/index.html')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create index "%s"'), $baseDir . '/plugin/index.html'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } } if (!$adminFS->is_dir($baseDir . '/plugin/language')) { if (!$adminFS->mkdir($baseDir . '/plugin/language')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create directory "%s"'), $baseDir . '/plugin/language'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/language/index.html')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create index "%s"'), $baseDir . '/plugin/language/index.html'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } } if (!$adminFS->is_dir($baseDir . '/plugin/templates')) { if (!$adminFS->mkdir($baseDir . '/plugin/templates')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create directory "%s"'), $baseDir . '/plugin/templates'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/templates/index.html')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create index "%s"'), $baseDir . '/plugin/templates/index.html'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } } if (!$adminFS->is_dir($baseDir . '/plugin/user')) { if (!$adminFS->mkdir($baseDir . '/plugin/user')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create directory "%s"'), $baseDir . '/plugin/user'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/user/index.html')) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Failed to create index "%s"'), $baseDir . '/plugin/user/index.html'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } } // install core plugins: foreach ($filesList as $file) { if (preg_match('/^.+\\.xml$/i', $file)) { $plgPath = $installFrom . (substr($installFrom, -1, 1) == '/' ? '' : '/') . $file; $plgXml = new \CBLib\Xml\SimpleXMLElement(trim(file_get_contents($plgPath))); if ($plgXml->getName() == 'cbinstall') { $plgDir = dirname($plgPath) . '/'; $plgInstaller = new cbInstallerPlugin(); if (!$plgInstaller->install($plgDir)) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Installing plugin failed with error: %s : %s'), $plgInstaller->i_elementname ? $plgInstaller->i_elementname : $file, $plgInstaller->getError()), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); return; } } } } $result = $adminFS->deldir(_cbPathName($installFrom . '/')); if ($result === false) { cbInstaller::renderInstallMessage(CBTxt::T('Deleting expanded tgz file directory failed with an error.'), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); } $tgzFileOS = _cbPathName($tgzFile, false); $result = $adminFS->unlink($tgzFileOS); if ($result === false) { cbInstaller::renderInstallMessage(sprintf(CBTxt::T('Deleting file %s failed with an error.'), $tgzFileOS), CBTxt::T('Installer - Error'), $installer->returnTo($option, '', 2)); } // adapt published fields to global CB config (regarding name type) _cbAdaptNameFieldsPublished($ueConfig); $htmlToDisplay = $_CB_framework->getUserState('com_comprofiler_install'); // clears the session buffer memory after installaion done: $_CB_framework->setUserState('com_comprofiler_install', ''); $installerXml = new SimpleXMLElement(file_get_contents($installerFile)); if (is_object($installerXml)) { $description = $installerXml->getElementByPath('description'); if ($description !== false) { echo '<h2>' . $description->data() . '</h2>'; } } echo $htmlToDisplay; echo '<div style="color:green;font-size:18px;font-weight:bold;margin-top:15px;margin-bottom:15px;">' . CBTxt::Th('Installation done.') . '</div>' . '<div style="color:green;font-size:18px;font-weight:bold;margin-top:15px;margin-bottom:15px;">' . CBTxt::Th('Now is a great time to checkout the <a href="[help_url]" target="_blank">Getting Started</a> resources.', null, array('[help_url]' => 'http://www.joomlapolis.com/documentation/community-builder/getting-started?pk_campaign=in-cb&pk_kwd=installedwelcomescreen')) . '</div>' . '<div style="margin-bottom:10px;">' . '<div style="font-size:12px;"><a href="http://www.joomlapolis.com/cb-solutions?pk_campaign=in-cb&pk_kwd=installedwelcomescreen" target="_blank">' . CBTxt::Th('Click here to see more CB Plugins (Languages, Fields, Tabs, Signup-Connect, Paid Memberships and over 30 more) by CB Team at joomlapolis.com') . '</a></div>' . '<div style="font-size:12px;"><a href="http://extensions.joomla.org/extensions/clients-a-communities/communities/210" target="_blank">' . CBTxt::Th('Click here to see our CB listing on the Joomla! Extensions Directory (JED) and find third-party add-ons for your website.') . '</a></div>' . '<div style="font-size:12px;margin:10px 0 25px;">or <a href="index.php?option=com_comprofiler&view=showconfig" class="btn btn-primary">' . CBTxt::Th('Start to Configure Community Builder') . '</a></div>' . '</div>'; $_CB_framework->setUserState("com_comprofiler_install", ''); }
/** * @param TableInterface $data * @param SimpleXMLElement $viewModel */ protected function savePluginViewOrder($data, $viewModel) { $ordering = $viewModel->xpath('//param[@type="ordering"]'); if (!$ordering) { $ordering = $viewModel->xpath('//field[@type="ordering"]'); } /** @var $ordering SimpleXMLElement|null */ if ($ordering) { foreach ($ordering as $node) { /** @var $node SimpleXMLElement */ $where = ''; $field = $node->attributes('name'); $orderingGroups = $node->getElementByPath('orderinggroups'); /** @var $orderingGroups SimpleXMLElement|null */ if ($orderingGroups) { foreach ($orderingGroups->children() as $group) { /** @var $group SimpleXMLElement */ $orderingFieldName = $group->attributes('name'); if ($group->getName() == 'ordering' && $orderingFieldName && array_key_exists($orderingFieldName, get_object_vars($data))) { $where .= $data->getDbo()->NameQuote($orderingFieldName) . " = " . $data->getDbo()->Quote($data->{$orderingFieldName}) . " AND "; } } } if ($data->hasFeature('ordered', $field)) { /** @var \CBLib\Database\Table\OrderedTable $data */ $data->updateOrder($where . $data->getDbo()->NameQuote($field) . " > -10000 AND " . $data->getDbo()->NameQuote($field) . " < 10000"); } } } }
/** * 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]; }
/** * @param string $url * @param string $file * @param int $duration * @return SimpleXMLElement|null */ public static function getFeedXML($url, $file, $duration = 12) { global $_CB_framework; cbimport('cb.snoopy'); $cache = $_CB_framework->getCfg('absolute_path') . '/cache/' . $file; $xml = null; if (file_exists($cache)) { if (!$duration || intval(($_CB_framework->now() - filemtime($cache)) / 3600) > $duration) { $request = true; } else { $xml = new SimpleXMLElement(trim(file_get_contents($cache))); $request = false; } } else { $request = true; } if ($request) { $s = new CBSnoopy(); $s->read_timeout = 30; $s->referer = $_CB_framework->getCfg('live_site'); @$s->fetch($url); if ((int) $s->status == 200) { try { $xml = new SimpleXMLElement($s->results); $xml->saveXML($cache); } catch (Exception $e) { } } } return $xml; }
/** * @param string $cbUri The CB-URI (cbo;,,,) * @param SimpleXMLElement $sourceElem The XML element from which the URL is computed * @param TableInterface $data The data of the object for dynamic URL request values * @param int $id The id of the current row * @param bool $htmlspecialchars If htmlspecialchars should be made for this * @param bool $inPage URL target: true: html (full page), false: raw (only center component content) * @return string The URL */ function drawUrl($cbUri, SimpleXMLElement $sourceElem, $data, $id, $htmlspecialchars = true, $inPage = true) { global $_CB_framework; if (!Access::authorised($sourceElem)) { return null; } $ui = $_CB_framework->getUi(); $actionName = null; if (substr($cbUri, 0, 4) == 'cbo:') { $subTaskValue = substr($cbUri, 4); switch ($subTaskValue) { /** @noinspection PhpMissingBreakStatementInspection */ case 'newrow': // $id = 0; // fallthrough: no break on purpose. // $id = 0; // fallthrough: no break on purpose. case 'rowedit': //TBD this is duplicate of below $baseUrl = 'index.php'; if ($this->_options['view'] == 'editPlugin') { $task = $this->_options['view']; } else { $task = 'editrow'; } $baseUrl .= '?option=' . $this->_options['option'] . '&view=' . $task; if (isset($this->_options['pluginid'])) { $baseUrl .= '&cid=' . $this->_options['pluginid']; } $url = $baseUrl . '&table=' . $this->_tableBrowserModel->attributes('name') . '&action=editrow'; // below: . '&tid=' . $id; break; case 'saveorder': case 'editrows': case 'deleterows': case 'copyrows': case 'updaterows': case 'publish': case 'unpublish': case 'enable': case 'disable': default: $url = 'javascript:cbDoListTask(this, ' . "'" . addslashes($this->taskName(false)) . "','" . addslashes($this->subtaskName(false)) . "','" . addslashes($this->subtaskValue($subTaskValue, false)) . "','" . addslashes($this->fieldId('id', null, false)) . "'" . ");"; break; } } elseif (substr($cbUri, 0, 10) == 'cb_action:') { $actionName = substr($cbUri, 10); $action = $this->_actions->getChildByNameAttr('action', 'name', $actionName); if ($action) { if (!Access::authorised($action)) { return null; } $requestNames = explode(' ', $action->attributes('request')); $requestValues = explode(' ', $action->attributes('action')); $parametersValues = explode(' ', $action->attributes('parameters')); $baseUrl = 'index.php'; $baseUrl .= '?'; $baseRequests = array('option' => 'option', 'view' => 'view', 'cid' => 'pluginid'); $urlParams = array(); foreach ($baseRequests as $breq => $breqOptionsValue) { if (!(in_array($breq, $requestNames) || in_array($breq, $parametersValues)) && isset($this->_options[$breqOptionsValue])) { $urlParams[$breq] = $breq . '=' . $this->_options[$breqOptionsValue]; } } for ($i = 0, $n = count($requestNames); $i < $n; $i++) { $urlParams[$requestNames[$i]] = $requestNames[$i] . '=' . $requestValues[$i]; // other parameters = paramvalues added below } $url = $baseUrl . implode('&', $urlParams); } else { $url = "#action_not_defined:" . $actionName; } } else { $url = cbUnHtmlspecialchars($cbUri); } if (cbStartOfStringMatch($url, 'index.php')) { // get the parameters of action/link from XML : $parametersNames = explode(' ', $sourceElem->attributes('parameters')); $parametersValues = explode(' ', $sourceElem->attributes('paramvalues')); $parametersValuesTypes = explode(' ', $sourceElem->attributes('paramvaluestypes')); // generate current action (and parameters ?) as cbprevstate $cbprevstate = array(); foreach ($this->_options as $req => $act) { if ($req && $act && !in_array($req, array('cbprevstate'))) { $cbprevstate[] = $req . '=' . $act; } } $parametersNames[] = 'cbprevstate'; $parametersValues[] = "'" . base64_encode(implode('&', $cbprevstate)) . "'"; // finally generate URL: for ($i = 0, $n = count($parametersNames); $i < $n; $i++) { $nameOfVariable = $parametersValues[$i]; if ($nameOfVariable != '') { if (isset($parametersValuesTypes[$i]) && $parametersValuesTypes[$i]) { if ($parametersValuesTypes[$i] == 'sql:field') { if (is_callable(array($data, 'get'))) { $nameOfVariable = $data->get($nameOfVariable); } else { $nameOfVariable = $data->{$nameOfVariable}; } } else { // $nameOfVariable untouched } } elseif (substr($nameOfVariable, 0, 1) == "'" && substr($nameOfVariable, -1) == "'") { $nameOfVariable = substr($nameOfVariable, 1, -1); } else { if (is_callable(array($data, 'get'))) { $nameOfVariable = $data->get($nameOfVariable); } else { $nameOfVariable = $data->{$nameOfVariable}; } } $url .= '&' . $parametersNames[$i] . '=' . urlencode($nameOfVariable); } } if ($ui == 2) { $url = $_CB_framework->backendUrl($url, $htmlspecialchars, $inPage ? 'html' : 'component'); } else { $url = cbSef($url, $htmlspecialchars, $inPage ? 'html' : 'component'); } } elseif ($htmlspecialchars) { $url = htmlspecialchars($url); } return $url; }
function plug_cbautoactions_install() { global $_CB_framework, $_CB_database; $table = '#__comprofiler_plugin_autoactions'; $fields = $_CB_database->getTableFields( $table ); if ( isset( $fields[$table]['field'] ) ) { $translateExists = isset( $fields[$table]['translate'] ); $excludeExists = isset( $fields[$table]['exclude'] ); $debugExists = isset( $fields[$table]['debug'] ); $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_autoactions' ); $_CB_database->setQuery( $query ); $rows = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__comprofiler_plugin_autoactions', 'id' ) ); /** @var $rows Table[] */ foreach ( $rows as $row ) { $row->set( 'trigger', str_replace( ',', '|*|', $row->get( 'trigger' ) ) ); $row->set( 'params', new Registry( $row->get( 'params' ) ) ); $newParams = new Registry(); if ( $row->get( 'field' ) ) { $fields = new Registry( $row->get( 'field' ) ); $operators = new Registry( $row->get( 'operator' ) ); $values = new Registry( $row->get( 'value' ) ); if ( $translateExists ) { $translates = new Registry( $row->get( 'translate' ) ); } else { $translates = null; } $conditionals = count( $fields ); if ( $conditionals ) { $conditions = array(); for ( $i = 0, $n = $conditionals; $i < $n; $i++ ) { $field = $fields->get( "field$i" ); $operator = $operators->get( "operator$i" ); $value = $values->get( "value$i" ); if ( $translateExists ) { $translate = $translates->get( "translate$i" ); } else { $translate = 0; } if ( $operator ) { $conditions[] = array( 'field' => $field, 'operator' => $operator, 'value' => $value, 'translate' => $translate ); } } if ( $conditions ) { $newConditionals = new Registry( $conditions ); $row->set( 'conditions', $newConditionals->asJson() ); } } $row->set( 'field', null ); $row->set( 'operator', null ); $row->set( 'value', null ); if ( $translateExists ) { $row->set( 'translate', null ); } } if ( $excludeExists ) { $exclude = $row->get( 'exclude' ); if ( $exclude ) { $newParams->set( 'exclude', $exclude ); $row->set( 'exclude', null ); } } if ( $debugExists ) { $debug = $row->get( 'debug' ); if ( $debug ) { $newParams->set( 'debug', $debug ); $row->set( 'debug', null ); } } if ( method_exists( 'cbautoactionsMigrate', $row->get( 'type' ) ) ) { call_user_func_array( array( 'cbautoactionsMigrate', $row->get( 'type' ) ), array( &$row, &$newParams ) ); } $row->set( 'params', $newParams->asJson() ); $row->store( true ); } $_CB_database->dropColumn( $table, 'field' ); $_CB_database->dropColumn( $table, 'operator' ); $_CB_database->dropColumn( $table, 'value' ); if ( $translateExists ) { $_CB_database->dropColumn( $table, 'translate' ); } if ( $excludeExists ) { $_CB_database->dropColumn( $table, 'exclude' ); } if ( $debugExists ) { $_CB_database->dropColumn( $table, 'debug' ); } } else { // Convert old |*| delimitered triggers to comma separated: $query = 'UPDATE ' . $_CB_database->NameQuote( '#__comprofiler_plugin_autoactions' ) . "\n SET " . $_CB_database->NameQuote( 'trigger' ) . " = REPLACE( " . $_CB_database->NameQuote( 'trigger' ) . ", " . $_CB_database->Quote( ',' ) . ", " . $_CB_database->Quote( '|*|' ) . " )"; $_CB_database->setQuery( $query ); $_CB_database->query(); } // Delete system actions that no longer exist: if ( isset( $fields[$table]['system'] ) ) { $xmlFile = $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/user/plug_cbautoactions/cbautoactions.xml'; if ( file_exists( $xmlFile ) ) { $xml = new SimpleXMLElement( trim( file_get_contents( $xmlFile ) ) ); $systemRows = $xml->xpath( '//database/table[@name="#__comprofiler_plugin_autoactions"]/rows/row[@index="system"]/@value' ); if ( $systemRows !== false ) { $systemIds = array(); foreach ( $systemRows as $systemRow ) { $systemIds[] = (string) $systemRow; } if ( $systemIds ) { $query = 'DELETE' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_autoactions' ) . "\n WHERE " . $_CB_database->NameQuote( 'system' ) . " NOT IN " . $_CB_database->safeArrayOfIntegers( $systemIds ) . "\n AND " . $_CB_database->NameQuote( 'system' ) . " != 0"; $_CB_database->setQuery( $query ); $_CB_database->query(); } } } } }