Example #1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $l = Util::getL10N('activity', $userLang);
         $l->forceLanguage($userLang);
         $this->helper->setL10n($l);
         $this->helper->setUser($user);
         $description = (string) $l->t('Personal activity feed for %s', $user);
         $activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
     } catch (\UnexpectedValueException $e) {
         $l = Util::getL10N('activity');
         $description = (string) $l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
Example #2
0
 /**
  * Shortcut for rendering a template
  * @deprecated 7.0.0 return a template response instead
  * @param string $templateName the name of the template
  * @param array $params the template parameters in key => value structure
  * @param string $renderAs user renders a full page, blank only your template
  *                          admin an entry in the admin settings
  * @param string[] $headers set additional headers in name/value pairs
  * @return \OCP\AppFramework\Http\TemplateResponse containing the page
  * @since 6.0.0
  */
 public function render($templateName, array $params = array(), $renderAs = 'user', array $headers = array())
 {
     $response = new TemplateResponse($this->appName, $templateName);
     $response->setParams($params);
     $response->renderAs($renderAs);
     foreach ($headers as $name => $value) {
         $response->addHeader($name, $value);
     }
     return $response;
 }
Example #3
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $this->l = $this->l10nFactory->get('activity', $userLang);
         $parser = new PlainTextParser($this->l);
         $this->helper->setL10n($this->l);
         $this->helper->setUser($user);
         $description = (string) $this->l->t('Personal activity feed for %s', $user);
         $response = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
         $data = $response['data'];
         $activities = [];
         foreach ($data as $activity) {
             $activity['subject_prepared'] = $parser->parseMessage($activity['subject_prepared']);
             $activity['message_prepared'] = $parser->parseMessage($activity['message_prepared']);
             $activities[] = $activity;
         }
     } catch (\UnexpectedValueException $e) {
         $this->l = $this->l10nFactory->get('activity');
         $description = (string) $this->l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subject_prepared' => $description]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $this->l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
 /**
  * If an AmpacheException is being caught, the appropiate ampache
  * exception response is rendered
  * @param Controller $controller the controller that is being called
  * @param string $methodName the name of the method that will be called on
  *                           the controller
  * @param \Exception $exception the thrown exception
  * @throws \Exception the passed in exception if it cant handle it
  * @return Response a Response object or null in case that the exception could not be handled
  */
 public function afterException($controller, $methodName, \Exception $exception)
 {
     if ($exception instanceof AmpacheException && $this->isAmpacheCall) {
         $response = new TemplateResponse($this->appname, 'ampache/error');
         $response->renderAs('blank');
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
         $response->setParams(array('code' => $exception->getCode(), 'message' => $exception->getMessage()));
         return $response;
     }
     throw $exception;
 }