protected function _beforeEdit(KControllerContextInterface $context) { $translator = $this->getObject('translator'); $data = $context->getRequest()->getData(); $model = $this->getModel(); $table = $model->getTable(); $entity = clone $model->fetch(); $fields = $entity->hasProperty('fields') ? $entity->fields : array(); $messages = array(); $parameters = array_merge($entity->getParameters()->toArray(), $data->has('parameters') ? $data->parameters : array()); foreach ($fields as $field) { if ($field->editable === false) { unset($parameters[$field->property]); continue; } if ($field->required) { switch ($field->element) { case 'email': if (!$parameters[$field->property]) { if (!$this->getObject('lib:filter.email')->validate($parameters[$field->property])) { $messages[] = $translator->translate('Please enter a valid E-mail address'); } } break; case 'boolean': if (!is_bool($parameters[$field->property])) { if (!is_numeric($parameters[$field->property])) { $messages[] = $translator->translate($field->label) . ' ' . $translator->translate('is a required field'); } $parameters[$field->property] = (bool) $parameters[$field->property]; } break; default: if (!$parameters[$field->property]) { $messages[] = $translator->translate($field->label) . ' ' . $translator->translate('is a required field'); } } } } $data->parameters = $parameters; if ($messages) { foreach ($messages as $message) { $context->getResponse()->addMessage($message, KControllerResponseInterface::FLASH_ERROR); } //TODO: Improve handeling error! $context->getRequest()->setData(array()); } }
public function _actionRender(KControllerContextInterface $context) { $data = array('url' => $context->getRequest()->query->get('url', 'url'), 'content-length' => false); if (!function_exists('curl_init')) { throw new RuntimeException('Curl library does not exist', KHttpResponse::SERVICE_UNAVAILABLE); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $data['url']); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 20); //CURLOPT_NOBODY changes the request from GET to HEAD curl_setopt($ch, CURLOPT_NOBODY, true); $response = curl_exec($ch); if (curl_errno($ch)) { throw new RuntimeException('Curl Error: ' . curl_error($ch), KHttpResponse::SERVICE_UNAVAILABLE); } $info = curl_getinfo($ch); if (isset($info['http_code']) && $info['http_code'] != 200) { throw new RuntimeException($data['url'] . ' Not Found', $info['http_code']); } if (isset($info['download_content_length'])) { $data['content-length'] = $info['download_content_length']; } curl_close($ch); //Set the data in the response $context->response->setContent(json_encode($data), 'application/json'); return $data; }
protected function _zaad(KControllerContextInterface $context) { $referrer = (string) $context->getRequest()->getReferrer(); $uri = JURI::getInstance($referrer); $router = clone JFactory::getApplication()->getRouter(); $query = $router->parse($uri); $referrer = $this->getObject('lib:http.url', array('url' => JURI::base() . 'index.php?' . http_build_query($query))); $context->getUser()->getSession()->set('referrer', urlencode($referrer)); }
/** * Load admin language file in forms since some of the layouts are shared * * @param KControllerContextInterface $context */ protected function _beforeRender(KControllerContextInterface $context) { $request = $context->getRequest(); if ($request->getFormat() === 'html' && $request->query->view === 'document' && $this->getView()->getLayout() === 'form') { $this->getObject('translator')->load('com://admin/docman'); } }
/** * Attach action. * * Creates a relationship between a resource and an existing attachment. * * @param KControllerContextInterface $context The context object. */ protected function _actionAttach(KControllerContextInterface $context) { $model = $this->getModel()->getRelationsModel(); $data = $context->getRequest()->getData(); $data[$context->identity_column] = $context->attachment->id; $relation = $model->create($data->toArray()); if (!$relation->save()) { throw new RuntimeException('Could not attach'); } }
protected function _checkUser(KControllerContextInterface $context) { if (!$context->user->isAuthentic()) { $message = $this->getObject('translator')->translate('You need to be logged in to access your document list'); $url = $context->getRequest()->getUrl(); $redirect = JRoute::_('index.php?option=com_users&view=login&return='.base64_encode($url), false); JFactory::getApplication()->redirect($redirect, $message, 'error'); } }
protected function _actionDone(KControllerContextInterface $context) { $token = $this->getHttpRequestVerifier()->verify($context->getRequest()->getQuery()->toArray()); $identity = $token->getDetails(); $model = $this->getPayum()->getStorage($identity->getClass())->find($identity); $this->setGateway($token->getGatewayName()); $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute($status = new GetHumanStatus($model)); $context->params = array('status' => $status, 'token' => $token); $this->getHttpRequestVerifier()->invalidate($token); $this->execute($status->getValue(), $context); }
protected function _actionCapture(KControllerContextInterface $context) { $token = $this->getHttpRequestVerifier()->verify($context->getRequest()->getQuery()->toArray()); $gateway = $this->getPayum()->getGateway($token->getGatewayName()); if ($reply = $gateway->execute(new Capture($token), true)) { if ($reply instanceof HttpRedirect) { header("Location: " . $reply->getUrl()); die; } throw new \LogicException('Unsupported reply', null, $reply); } $this->getHttpRequestVerifier()->invalidate($token); $context->getResponse()->setRedirect($token->getAfterUrl()); }
protected function _actionPrepare(KControllerContextInterface $context) { $message = ''; $type = KControllerResponseInterface::FLASH_SUCCESS; if ($this->hasHandler()) { $gateway_name = $context->getRequest()->getData()->payment_gateway; $method = 'prepareGateway' . ucfirst($gateway_name); $this->{$method}($context); $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken($gateway_name, $this->getPayment(), 'payment_done'); $location = $captureToken->getTargetUrl(); } else { $location = $context->getRequest()->getReferrer(); $message = 'No sales plugin enabled for: ' . $this->getRequestComponent(); $type = KControllerResponseInterface::FLASH_ERROR; } $context->getResponse()->setRedirect($location, $message, $type); }
/** * Load the model state from the request * * This functions merges the request information with any model state information that was saved in the session and * returns the result. * * @param KControllerContextInterface $context The active controller context * @return void */ protected function _beforeBrowse(KControllerContextInterface $context) { $query = $context->getRequest()->query; $query->add((array) $context->user->get($this->_getStateKey($context))); $this->getModel()->getState()->setValues($query->toArray()); }
/** * Entity slug has been changed which means the old URL will lead to 404. Rewrite it. * @todo this needs to be cleaned up * @param KControllerContextInterface $context */ protected function _updateReferrer(KControllerContextInterface $context) { $entity = $context->result; if ($entity instanceof KModelEntityInterface && $this->_old_slug && $this->_old_slug !== $entity->slug) { $referrer = $context->getRequest()->getReferrer(); $old_alias = $entity->id.'-'.$this->_old_slug; $new_alias = $entity->id.'-'.$entity->slug; if (strpos($referrer, $old_alias) !== false) { $referrer = strtr($referrer, array( $old_alias => $new_alias, $this->_old_slug => $entity->slug )); // Set the referrer in request and as the redirect $context->request->setReferrer($referrer); } $referrer_cookie = $this->getReferrer($context); if (strpos($referrer_cookie, $old_alias) !== false) { // Also update referrer stored in the cookie $referrer_cookie = strtr($referrer_cookie, array( $old_alias => $new_alias, $this->_old_slug => $entity->slug )); // Unset the old referrer since it's a 404 now $this->_unsetReferrer($context); // Temporarily change the referrer so that setReferrer can grab it $context->request->setReferrer($referrer_cookie); $this->setReferrer($context); $context->request->setReferrer($referrer); } if ($context->action === 'apply' || $entity->getStatus() === KModelEntityInterface::STATUS_FAILED) { $context->response->setRedirect($referrer); } else { $context->response->setRedirect($referrer_cookie); } } }