예제 #1
0
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $map = function ($value) {
         return ['value' => $value, 'label' => $value];
     };
     if ($req->isGet()) {
         $this->view['tpe_survey'] = ['already_using_tpe' => self::$alreadyUsingTpe, 'knowledge_levels' => array_map($map, self::$knowledgeLevels), 'assets_in_use' => array_map($map, self::$assetsInUse), 'software_in_use' => self::$softwareInUse, 'use_case' => self::$useCase];
     }
     return $next($req, $res);
 }
 public function authorizeSkillRoute(Request $request, Response $response, callable $next)
 {
     // Authorize portfolio middleware
     $args = $request->getAttribute('routeInfo')[2];
     if (!$args || $request->isXhr() && $request->isGet()) {
         return $next($request, $response);
     }
     $count = $this->data(Models\MemberSkills::class)->count(['member_skill_id' => (int) $args['id'], 'user_id' => $this->session->get('user_id')]);
     if ($count < 1) {
         $this->flash->addMessage('warning', 'Permission denied.');
         return $response->withRedirect($this->router->pathFor('membership-account'));
     }
     return $next($request, $response);
 }
 /**
  * @param \Slim\Http\Request $request
  * @return bool
  */
 private function isAcceptable(Request $request)
 {
     $args = $request->getAttribute('routeInfo')[2];
     return !$args || $request->isXhr() && $request->isGet();
 }
예제 #4
0
 protected function isGet()
 {
     return $this->request->isGet();
 }
예제 #5
0
 /**
  * Dislay information about the video.
  *
  * @param Request  $request  PSR-7 request
  * @param Response $response PSR-7 response
  *
  * @return Response HTTP response
  */
 public function video(Request $request, Response $response)
 {
     $params = $request->getQueryParams();
     $this->config = Config::getInstance();
     if (isset($params['url'])) {
         if (isset($params['audio'])) {
             try {
                 $url = $this->download->getURL($params['url'], 'mp3[protocol^=http]');
                 return $response->withRedirect($url);
             } catch (\Exception $e) {
                 $response = $response->withHeader('Content-Disposition', 'attachment; filename="' . $this->download->getAudioFilename($params['url'], 'bestaudio/best') . '"');
                 $response = $response->withHeader('Content-Type', 'audio/mpeg');
                 if ($request->isGet()) {
                     $process = $this->download->getAudioStream($params['url'], 'bestaudio/best');
                     $response = $response->withBody(new Stream($process));
                 }
                 return $response;
             }
         } else {
             $video = $this->download->getJSON($params['url']);
             if ($this->container instanceof Container) {
                 $this->container->view->render($response, 'video.tpl', ['video' => $video, 'class' => 'video', 'title' => $video->title, 'description' => 'Download "' . $video->title . '" from ' . $video->extractor_key]);
             }
         }
     } else {
         return $response->withRedirect($this->container->get('router')->pathFor('index'));
     }
 }