Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * Performs a table action on a click in table
  *
  * @return void
  * @throws \Exception
  */
 protected function _performTableActions()
 {
     global $_CB_framework;
     if (!isset($_REQUEST[$this->name])) {
         return;
     }
     $subtask = cbGetParam($_REQUEST[$this->name], 'subtask', '');
     if (!$subtask) {
         return;
     }
     $task_parsed = explode('/', $subtask);
     $cid = cbGetParam($_REQUEST[$this->name], 'idcid', array());
     if (!is_array($cid)) {
         $ocid = $cid;
         $cid = array();
         $cid[] = $ocid;
     }
     switch ($task_parsed[0]) {
         case 'orderup':
         case 'orderdown':
         case 'saveorder':
             if ($this->listFieldsRows) {
                 if (isset($task_parsed[1])) {
                     $field = $task_parsed[1];
                     $fieldNode = $this->listFieldsRows->getChildByNameAttr('field', 'name', $field);
                     if (!$fieldNode) {
                         $fieldNode = $this->listFieldsRows->getChildByNameAttr('param', 'name', $field);
                     }
                 } else {
                     $field = null;
                     $fieldNode = false;
                 }
                 if (!$fieldNode || $fieldNode->attributes('type') !== 'ordering' || !Access::authorised($fieldNode)) {
                     $_CB_framework->enqueueMessage(CBTxt::T('This field can not ordered'), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 if ($task_parsed[0] != 'saveorder') {
                     $dataModelValue = $cid[0];
                 } else {
                     $dataModelValue = null;
                 }
                 $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                 if (!$row) {
                     $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                     return;
                 }
                 if ($task_parsed[0] == 'saveorder') {
                     $order = cbGetParam($_REQUEST[$this->name], $field, array(0));
                 }
                 $where = '';
                 $orderinggroups = $fieldNode->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($row))) {
                             if ($task_parsed[0] != 'saveorder') {
                                 $where .= $this->_db->NameQuote($orderingFieldName) . ' = ' . XmlTypeCleanQuote::sqlCleanQuote($row->{$orderingFieldName}, $group->attributes('type'), $this->_pluginParams, $this->_db) . ' AND ';
                             } else {
                                 $where .= $orderingFieldName . "='\$row->" . $orderingFieldName . "' AND ";
                             }
                         }
                     }
                 }
                 if ($task_parsed[0] != 'saveorder') {
                     $inc = $task_parsed[0] == 'orderup' ? -1 : 1;
                     /** @var OrderedTable $row */
                     $row->move($inc, $where . $field . " > -10000 AND " . $field . " < 10000 ", $field);
                 } else {
                     $this->saveOrder($cid, $row, $order, "\$condition = \"" . $where . $field . " > -10000 AND " . $field . " < 10000 \";", $field);
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_ORDER_SUCCESS', 'Row ordered successfully!|%%COUNT%% rows ordered successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'publish':
         case 'unpublish':
         case 'enable':
         case 'disable':
         case 'setfield':
         case 'doaction':
             if ($this->listFieldsRows) {
                 $field = null;
                 switch ($task_parsed[0]) {
                     case 'publish':
                     case 'unpublish':
                         $value = $task_parsed[0] == 'publish' ? 1 : 0;
                         $field = 'published';
                         break;
                     case 'enable':
                     case 'disable':
                         $value = $task_parsed[0] == 'enable' ? 1 : 0;
                         $field = 'enabled';
                         break;
                     case 'setfield':
                         $value = $task_parsed[2];
                         break;
                     case 'doaction':
                         $value = null;
                         break;
                     default:
                         throw new \Exception(__FUNCTION__ . ': Impossible value');
                 }
                 if (isset($task_parsed[1])) {
                     $field = $task_parsed[1];
                 }
                 /** @var SimpleXMLElement $fieldNode */
                 $fieldNode = $this->listFieldsRows->xpath('(//field[@name="' . $field . '"][@onclick="toggle"])[last()]');
                 if (!$fieldNode) {
                     $fieldNode = $this->listFieldsRows->xpath('(//param[@name="' . $field . '"][@onclick="toggle"])[last()]');
                 }
                 if (!$fieldNode) {
                     // We're not a field toggle so lets check if we're a menu item for permission/usage checks:
                     $fieldNode = $this->toolbarmenu->xpath('(//menu[@name="' . $field . '"])[last()]');
                 }
                 if (!$fieldNode || !Access::authorised($fieldNode[0])) {
                     $_CB_framework->enqueueMessage(CBTxt::T('THIS_FIELD_CAN_NOT_TOGGLE_TASK', 'This field can not toggle: [task]', array('[task]' => $task_parsed[0])), 'error');
                     return;
                 }
                 $fieldNode = $fieldNode[0];
                 $taskName = CBTxt::T($fieldNode->attributes('label'));
                 if ($task_parsed[0] == 'setfield') {
                     // Check field value if allowed:
                     $this->registryEditVew->resolveXmlParamType($fieldNode);
                     if ($fieldNode->getChildByNameAttributes('option')) {
                         $valueNode = $fieldNode->getAnyChildByNameAttr('option', 'index', $value);
                         if (!$valueNode) {
                             $valueNode = $fieldNode->getAnyChildByNameAttr('option', 'value', $value);
                         }
                         if ($valueNode) {
                             $valueLabel = CBTxt::T($valueNode->data());
                             if ($valueLabel) {
                                 $taskName = $valueLabel;
                             }
                         } else {
                             $_CB_framework->enqueueMessage(CBTxt::T('This field can not be set to that value'), 'error');
                             return;
                         }
                     }
                 }
                 if (!$taskName) {
                     $taskName = $task_parsed[0];
                 }
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => strtolower($taskName))), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $c) {
                     $dataModelValue = $c;
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     if ($task_parsed[0] == 'doaction') {
                         $this->registryEditVew->pushModelOfData($row);
                         $toggle = $this->registryEditVew->_form_private($field, $value, $fieldNode, null);
                         $this->registryEditVew->popModelOfData();
                         if (!$toggle) {
                             $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                             return;
                         }
                     } elseif ($row->{$field} != $value) {
                         if (is_callable(array($row, 'historySetMessage'))) {
                             $row->historySetMessage(ucfirst($task_parsed[0]) . ' ' . $field . ' from administration backend');
                         }
                         if ($fieldNode->attributes('class') && $fieldNode->attributes('method')) {
                             $this->registryEditVew->pushModelOfData($row);
                             $toggle = $this->registryEditVew->_form_private($field, $value, $fieldNode, null);
                             $this->registryEditVew->popModelOfData();
                             if (!$toggle) {
                                 $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                 return;
                             }
                         } elseif ($row->hasFeature('checkout')) {
                             /** @var CheckedOrderedTable $row */
                             if (!$row->isCheckedOut($_CB_framework->myId())) {
                                 $row->{$field} = $value;
                                 if ($row->check()) {
                                     if (!$row->store()) {
                                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                         return;
                                     }
                                 } else {
                                     $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                     return;
                                 }
                                 $row->checkin();
                             }
                         } else {
                             $row->{$field} = $value;
                             if ($row->check()) {
                                 if (!$row->store()) {
                                     $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                     return;
                                 }
                             } else {
                                 $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                 return;
                             }
                         }
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_TASK_SUCCESS', '{1} Row [task] successfully!|%%COUNT%% rows [task] successfully!', array('%%COUNT%%' => count($cid), '[task]' => strtolower($taskName))));
             }
             break;
         case 'editrows':
             if ($this->listFieldsRows) {
                 if (count($cid) != 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'edit')), 'error');
                     return;
                 }
                 if (isset($task_parsed[1])) {
                     $field = $task_parsed[1];
                 } else {
                     $field = 'tid';
                 }
                 if ($this->_options['view'] == 'editPlugin') {
                     $task = $this->_options['view'];
                 } else {
                     $task = 'editrow';
                 }
                 $baseUrl = 'index.php?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&' . urlencode($field) . '=' . urlencode($cid[0]);
                 cbRedirect($url);
             }
             break;
         case 'deleterows':
             if ($this->listFieldsRows) {
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'delete')), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $id) {
                     $dataModelValue = $id;
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     if ($row->canDelete($dataModelValue)) {
                         if (!$row->delete($dataModelValue)) {
                             $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_DELETE_ROW_ID_BECAUSE_ERROR', 'Cannot delete row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                             return;
                         }
                     } else {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_DELETE_ROW_ID_BECAUSE_ERROR', 'Cannot delete row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_DELETED_SUCCESS', 'Row deleted successfully!|%%COUNT%% rows deleted successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'batchrows':
             if ($this->listFieldsRows) {
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'batch')), 'error');
                     return;
                 }
                 $postData = array();
                 foreach ($this->_batchPossibilitesArray as $key => $value) {
                     // <batchprocess><batch>
                     if (!$this->isValueEmpty($value['internalvalue'])) {
                         $field = $value['valuefield'];
                         $postData[$field] = $value['internalvalue'];
                     }
                     // Reset back to null as we don't want the values reselected on display:
                     $this->_batchPossibilitesArray[$key]['value'] = null;
                     $this->_batchPossibilitesArray[$key]['internalvalue'] = $value['value'];
                 }
                 if (count($postData) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('Nothing to process'), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $id) {
                     $dataModelValue = $id;
                     /** @var $row TableInterface */
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     $rowPost = array();
                     foreach ($postData as $key => $value) {
                         if (property_exists($row, $key)) {
                             $rowPost[$key] = is_array($value) ? json_encode($value) : $value;
                         }
                     }
                     if (count($rowPost) < 1) {
                         $_CB_framework->enqueueMessage(CBTxt::T('Nothing to process'), 'error');
                         return;
                     }
                     if (!$row->bind($rowPost)) {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_BATCH_PROCESS_ROW_ID_ID_BECAUSE_ERROR', 'Cannot batch process row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                     if (!$row->check()) {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_BATCH_PROCESS_ROW_ID_ID_BECAUSE_ERROR', 'Cannot batch process row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                     if (!$row->store()) {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_BATCH_PROCESS_ROW_ID_ID_BECAUSE_ERROR', 'Cannot batch process row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_SAVED_SUCCESS', 'Row saved successfully!|%%COUNT%% rows saved successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'copyrows':
             if ($this->listFieldsRows) {
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'copy')), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $id) {
                     $dataModelValue = $id;
                     /** @var $row TableInterface */
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     if ($row->canCopy()) {
                         if (!$row->copy()) {
                             $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_COPY_ROW_ID_ID_BECAUSE_ERROR', 'Cannot copy row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                             return;
                         }
                     } else {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_COPY_ROW_ID_ID_BECAUSE_ERROR', 'Cannot copy row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_COPIED_SUCCESS', 'Row copied successfully!|%%COUNT%% rows copied successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'action':
             if ($this->listFieldsRows) {
                 if (count($cid) != 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => isset($task_parsed[1]) ? $task_parsed[1] : 'action')), 'error');
                     return;
                 }
                 if (isset($task_parsed[1])) {
                     if (isset($task_parsed[2])) {
                         $field = $task_parsed[2];
                     } else {
                         $field = 'tid';
                     }
                     $baseUrl = 'index.php?option=' . $this->_options['option'] . '&view=' . $this->_options['view'];
                     if (isset($this->_options['pluginid'])) {
                         $baseUrl .= '&cid=' . $this->_options['pluginid'];
                     }
                     $url = $baseUrl . '&table=' . $this->_tableBrowserModel->attributes('name') . '&action=' . urlencode($task_parsed[1]) . '&' . urlencode($field) . '=' . urlencode($cid[0]);
                     cbRedirect($url);
                 }
             }
             break;
         default:
             break;
     }
     //TBD cbRedirect( $_CB_framework->backendUrl( 'index.php?option=com_comprofiler&task=showPlugins', $msg ) );
 }
	/**
	 * Implements a form xpath-type field for showing a given xpath value
	 *
	 * @param  string              $name          The name of the form element
	 * @param  string              $value         The value of the element
	 * @param  SimpleXMLElement    $node          The xml element for the parameter
	 * @param  string              $control_name  The control name
	 * @return string                             The html for the element
	 */
	function _form_xpath( /** @noinspection PhpUnusedParameterInspection */ $name, $value, &$node, $control_name ) {
		$fromNode				=	$node->attributes( 'path' );
		$fromFile				=	$node->attributes( 'file' );
		$translate				=	$node->attributes( 'translate' );

		$return					=	null;

		if ( $fromNode && ( $fromFile !== null ) ) {
			$this->substituteName( $fromFile, true );
			$this->substituteName( $fromNode, false );

			if ( $fromFile !== '' ) {
				$fromFile		=	static::pathFromXML( $fromFile . '.xml', $node, $this->_pluginObject );
			}

			if ( ( $fromFile === '' ) || is_readable( $fromFile ) ) {
				if ( $fromFile === '' ) {
					$fromRoot	=	$node;
				} else {
					$fromRoot	=	new SimpleXMLElement( $fromFile, LIBXML_NONET | ( defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0 ), true );
				}

				/** @var SimpleXMLElement[] $xmlPath */
				$xmlPath		=	$fromRoot->xpath( $fromNode );

				if ( $xmlPath && count( $xmlPath ) ) {
					$return		=	$xmlPath[0]->data();
				}

				if ( $translate == 'yes' ) {
					$return		=	CBTxt::Th( $return );
				}
			}
		}

		return $return;
	}
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();
				}
			}
		}
	}
}
 /**
  * @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");
             }
         }
     }
 }
Exemple #6
0
 /**
  * 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=&quot;paymentstatusinformation&quot;]" 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);
     }
 }
	/**
	 * 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;
	}
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;
}