/** * Handles an InputInterface\input request and returns the corresponding Output in the container * Raises an Core\Exception if task to do is not known or not authorized. * * @param string $method * @return void * * @throws \Exception */ public function execute($method) { $route = array('option' => 'com_comprofiler', 'view' => $this->options['view'], 'action' => $method, 'method' => $this->input->get('act', 'edit', GetterInterface::COMMAND)); /** @var \CBLib\AhaWow\Controller\Controller $ahaWowController */ $ahaWowController = $this->di->get('CBLib\\AhaWow\\Controller\\Controller', array('options' => $this->options)); $ahaWowController->dispatchRoute($route); }
/** * Returns an array of all current params * * @return array */ public function asArray() { $inputVars = $this->input->asArray(); $sessionVars = $this->session->asArray(); $namedSessionVars = array(); $sessionKeyPrefixLen = strlen($this->sessionKeyPrefix); foreach ($sessionVars as $k => $v) { if (substr($k, 0, $sessionKeyPrefixLen) !== $this->sessionKeyPrefix) { continue; } $namedSessionVars[substr($k, $sessionKeyPrefixLen)] = $v; } // Return union of keyed inputs and session (with priority to input): return $inputVars + $namedSessionVars; }
/** * Parses the $input for the main routing arguments * * @param InputInterface $input Input * @return array Keyed array with the 3 main routing arguments */ protected function parseRoutingArgs(InputInterface $input) { return $input->get(array('option', 'view', 'task'), null, GetterInterface::COMMAND); }
/** * view param type _form_TYPE implementation * * @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 mixed The value */ protected function _form__get_password( $name, $value, /** @noinspection PhpUnusedParameterInspection */ $node, /** @noinspection PhpUnusedParameterInspection */ $control_name ) { // Temporary default method for backwards-compatibility: return $this->input->get( $this->inputControlName( $name ), $value, GetterInterface::RAW ); }
/** * Returns a provider button * * @param string $provider * @param int $horizontal * @return null|string */ public function getButton( $provider, $horizontal = 1 ) { global $_CB_framework; if ( ! ( $provider && isset( $this->providers[$provider] ) ) ) { return null; } $fieldName = $this->providers[$provider]['field']; $siteName = $this->providers[$provider]['name']; $iconClass = $this->providers[$provider]['icon']; $buttonClass = $this->providers[$provider]['button']; $user = CBuser::getMyUserDataInstance(); $style = (int) $this->params->get( $provider . '_button_style', 2, GetterInterface::INT ); if ( $style == 1 ) { $horizontal = 1; } static $returnUrl = null; if ( ! isset( $returnUrl ) ) { $returnUrl = $this->input->get( 'return', null, GetterInterface::BASE64 ); if ( $returnUrl ) { $returnUrl = base64_decode( $returnUrl ); } else { $isHttps = ( isset( $_SERVER['HTTPS'] ) && ( ! empty( $_SERVER['HTTPS'] ) ) && ( $_SERVER['HTTPS'] != 'off' ) ); $returnUrl = 'http' . ( $isHttps ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST']; if ( ( ! empty( $_SERVER['PHP_SELF'] ) ) && ( ! empty( $_SERVER['REQUEST_URI'] ) ) ) { $returnUrl .= $_SERVER['REQUEST_URI']; } else { $returnUrl .= $_SERVER['SCRIPT_NAME']; if ( isset( $_SERVER['QUERY_STRING'] ) && ( ! empty( $_SERVER['QUERY_STRING'] ) ) ) { $returnUrl .= '?' . $_SERVER['QUERY_STRING']; } } } $returnUrl = cbUnHtmlspecialchars( preg_replace( '/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', preg_replace( '/eval\((.*)\)/', '', htmlspecialchars( urldecode( $returnUrl ) ) ) ) ); if ( preg_match( '/index\.php\?option=com_comprofiler&view=login|index\.php\?option=com_comprofiler&view=pluginclass&plugin=cbconnect/', $returnUrl ) ) { $returnUrl = 'index.php'; } $returnUrl = base64_encode( $returnUrl ); } $return = null; if ( $this->params->get( $provider . '_enabled', false, GetterInterface::BOOLEAN ) ) { if ( $user->get( 'id' ) ) { if ( $this->params->get( $provider . '_link', true, GetterInterface::BOOLEAN ) && ( ! $user->get( $fieldName ) ) ) { $link = $this->params->get( $provider . '_button_link', null, GetterInterface::STRING ); $return = '<button class="cbConnectButton cbConnectButton' . ucfirst( $provider ) . ' btn btn-' . $buttonClass . ' btn-sm' . ( ! $horizontal ? ' btn-block' : null ) . '" onclick="window.location=\'' . $_CB_framework->pluginClassUrl( $this->plugin->element, false, array( 'provider' => $provider, 'action' => 'authenticate', 'return' => $returnUrl ) ) . '\'; return false;" title="' . htmlspecialchars( CBTxt::T( 'LINK_YOUR_SITENAME_ACCOUNT', 'Link your [sitename] account', array( '[sitename]' => $siteName ) ) ) . '">' . ( in_array( $style, array( 1, 2 ) ) ? '<span class="fa fa-' . $iconClass . ' fa-lg' . ( $style != 1 ? ' cbConnectButtonPrefix' : null ) . '"></span>' : null ) . ( in_array( $style, array( 2, 3 ) ) ? ( $link ? $link : CBTxt::T( 'LINK_WITH_SITENAME', 'Link with [sitename]', array( '[sitename]' => $siteName ) ) ) : null ) . '</button>' . ( $horizontal ? ' ' : null ); } } else { $signin = $this->params->get( $provider . '_button_signin', null, GetterInterface::STRING ); $return = '<button class="cbConnectButton cbConnectButton' . ucfirst( $provider ) . ' btn btn-' . $buttonClass . ' btn-sm' . ( ! $horizontal ? ' btn-block' : null ) . '" onclick="window.location=\'' . $_CB_framework->pluginClassUrl( $this->plugin->element, false, array( 'provider' => $provider, 'action' => 'authenticate', 'return' => $returnUrl ) ) . '\'; return false;" title="' . htmlspecialchars( CBTxt::T( 'LOGIN_WITH_YOUR_SITENAME_ACCOUNT', 'Login with your [sitename] account', array( '[sitename]' => $siteName ) ) ) . '">' . ( in_array( $style, array( 1, 2 ) ) ? '<span class="fa fa-' . $iconClass . ' fa-lg' . ( $style != 1 ? ' cbConnectButtonPrefix' : null ) . '"></span>' : null ) . ( in_array( $style, array( 2, 3 ) ) ? ( $signin ? $signin : CBTxt::T( 'SIGN_IN_WITH_SITENAME', 'Sign in with [sitename]', array( '[sitename]' => $siteName ) ) ) : null ) . '</button>' . ( $horizontal ? ' ' : null ); } } return $return; }
/** * Performs a table action on a click in table * * @return void * @throws \Exception */ protected function _performTableActions() { global $_CB_framework; $subtask = $this->input->get($this->name . '.' . 'subtask', '', GetterInterface::STRING); if (!$subtask) { return; } $task_parsed = explode('/', $subtask); $cid = $this->input->get($this->name . '.' . 'idcid', array(), GetterInterface::RAW); if (!is_array($cid)) { $cid = array($cid); } 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 = $this->input->get($this->name . '.' . $field, array(0), GetterInterface::RAW); } $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; } // Fix multi-selects and multi-checkboxes arrays to |*|-delimited strings: $postData = ActionController::recursiveMultiSelectFix($postData); $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 ) ); }