示例#1
0
 protected function _afterRead(KControllerContextInterface $context)
 {
     if ($context->result->locale !== $this->_locale) {
         $message = 'COM_TRANSLATIONS_ONLY_AVAILABLE_IN_' . strtoupper(substr($context->result->locale, 0, 2));
         $context->getResponse()->addMessage($this->getObject('translator')->translate($message), KControllerResponseInterface::FLASH_WARNING);
     }
 }
示例#2
0
 /**
  * Avoid getting redirected to the configs view. It doesn't exist.
  */
 protected function _setRedirect(KControllerContextInterface $context)
 {
     $response = $context->getResponse();
     if ($response->isRedirect()) {
         $url = $response->getHeaders()->get('Location');
         if (strpos($url, 'view=configs') !== false) {
             $response->setRedirect(str_replace('view=configs', 'view=documents', $url));
         }
     }
 }
示例#3
0
 /**
  * Avoid getting redirected to the configs view. It doesn't exist.
  */
 protected function _setRedirect(KControllerContextInterface $context)
 {
     $response = $context->getResponse();
     if ($response->isRedirect()) {
         if ($context->action == 'cancel') {
             $response->setRedirect(JURI::base());
         } else {
             $response->setRedirect('index.php?option=com_ohanah&view=events');
         }
     }
 }
示例#4
0
    /**
     * Makes sure the redirect URL won't be unauthorized or a nonexistent one
     *
     * @param KControllerContextInterface $context
     */
    protected function _afterApply(KControllerContextInterface $context)
    {
        $entity = $context->result;

        // User cannot edit the document she just added
        if ($entity instanceof KModelEntityInterface && $entity->isPermissible() && !$entity->canPerform('edit'))
        {
            $translator = $this->getObject('translator');

            $message    = $translator->translate('Document saved');
            $context->getResponse()->addMessage($message, KControllerResponse::FLASH_SUCCESS);

            $message    = $translator->translate('You have been redirected to this page since you do not have permissions to edit the document that you have just created.');
            $context->getResponse()->addMessage($message, KControllerResponse::FLASH_SUCCESS);

            $context->response->setRedirect($this->getReferrer($context));
        }

        $this->_updateReferrer($context);
    }
示例#5
0
 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());
 }
示例#6
0
 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());
     }
 }
示例#7
0
    protected function _afterAdd(KControllerContextInterface $context)
    {
        if ($context->getResponse()->getStatusCode() == KHttpResponse::CREATED)
        {
            $page = JFactory::getApplication()->getMenu()->getItem($this->getRequest()->query->Itemid);
            $translator = $this->getObject('translator');

            $emails = $page->params->get('notification_emails');
            if (!empty($emails))
            {
                $emails = explode("\n", $emails);

                $config	= JFactory::getConfig();
                $from_name = $config->get('fromname');
                $mail_from = $config->get('mailfrom');
                $sitename = $config->get('sitename');
                $subject   = $translator->translate('A new document was submitted for you to review on {sitename}', array(
                    'sitename' => $sitename
                ));

                $admin_link  = JURI::root().'administrator/index.php?option=com_docman&view=documents';
                $title       = $context->result->title;
                $admin_title = $translator->translate('Document Manager');

                foreach ($emails as $email)
                {
                    $body = $translator->translate('Submit notification mail body', array(
                        'title'    => $title,
                        'sitename' => $sitename,
                        'url'      => $admin_link,
                        'url_text' => $admin_title
                    ));

                    JFactory::getMailer()->sendMail($mail_from, $from_name, $email, $subject, $body, true);
                }
            }
        }
    }
示例#8
0
 protected function _afterEdit(KControllerContextInterface $context)
 {
     $status_code = $context->getResponse()->getStatusCode();
     if ($status_code < 200 || $status_code >= 300) {
         return;
     }
     if ($this->_regenerate) {
         foreach ($context->result as $entity) {
             $this->_saveThumbnail($entity);
         }
     }
 }
示例#9
0
    protected function _cleanUp(KControllerContextInterface $context)
    {
        if ($context->getResponse()->getStatusCode() !== KHttpResponse::CREATED)
        {
            try
            {
                if ($this->_uploaded instanceof KModelEntityInterface) {
                    $this->_uploaded->delete();
                }

            } catch (Exception $e) {
                // Well, we tried
            }
        }
    }
示例#10
0
 protected function _afterAttach(KControllerContextInterface $context)
 {
     $context->getResponse()->setStatus(KHttpResponse::NO_CONTENT);
 }