Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # .htaccess
- ```
- <FilesMatch "\.(pdf)$">
- RewriteRule (.+\.pdf)$ /extensions/local/nesec/pdfManager/pdf-manager.php
- </FilesMatch>
- ```
- # /extensions/local/nesec/pdfManager/pdf-manager.php
- ```
- // since loading the pdf is outside the app I'm manually including the main index.php file to initate bolt cms
- require $_SERVER['DOCUMENT_ROOT'] . '/index.php';
- ```
- # Extension.php
- where the auth happens
- ```
- ...
- // execute if URI contains .pdf extenstion
- if (preg_match('/\.pdf/i', $_SERVER['REQUEST_URI'])) {
- $this->app->match($_SERVER['REQUEST_URI'], array($this, 'initExtension'));
- } else {
- return;
- }
- ...
- public function initExtension(){
- // check if file is inside broker-pdf limited access directory
- $brokerDir = preg_match('/broker\-pdf/', $_SERVER['REQUEST_URI']);
- // check auth or render pdf
- if ($brokerDir) {
- $this->isAuth();
- } else {
- $this->renderPdf();
- }
- }
- ...
- public function isAuth(){
- // bolt authentication function
- if ( $this->app['users']->isValidSession() ) {
- $this->renderPdf();
- } else {
- // redirect to login page
- header( 'Location: ' . $app['resources']->getUrl('hosturl') . '/login' );
- }
- }
- ...
- public function renderPdf(){
- header("Content-type:application/pdf");
- // echo pdf content;
- echo file_get_contents($this->app['resources']->getPath('root') . $this->app['request']->getPathInfo());
- // prevent app from fully executing
- exit();
- }
- ...
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement