-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
31 lines (28 loc) · 1.08 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* Leafpub: Simple, beautiful publishing. (https://leafpub.org)
*
* @link https://github.com/Leafpub/leafpub
* @copyright Copyright (c) 2016 Leafpub Team
* @license https://github.com/Leafpub/leafpub/blob/master/LICENSE.md (GPL License)
*/
namespace Leafpub\Plugins\MobileSwitch;
use Leafpub\Leafpub,
Leafpub\Plugin\APlugin;
class Plugin extends APlugin {
public function __construct(\Slim\App $app){
$app->getContainer()['settings']['determineRouteBeforeAppMiddleware'] = true;
parent::__construct($app);
}
public function __invoke($request, $response, $next){
$route = $request->getAttribute('route');
if ($route && $route->getPattern() === '/{post}'){
$uri = $request->getUri();
$s = "/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|PlayBook|Kindle|Windows Phone/i";
if (preg_match($s, $request->getServerParam('HTTP_USER_AGENT'))){
return $response->withRedirect($uri . '/amp');
}
}
return $next($request, $response);
}
}