Last active
August 29, 2015 14:21
-
-
Save loulou2u/cfd37b946e0cffbad72a to your computer and use it in GitHub Desktop.
Restrict Access to Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The custom app below redirects files tagged as "private" to a .htaccess protected directory | |
<?php | |
$_LW->REGISTERED_APPS['protect_files']=array( | |
'title'=>'Protect Files', | |
'handlers'=>array('onLoad') | |
); | |
class LiveWhaleApplicationProtectFiles { | |
public function onLoad() { | |
global $_LW; | |
// if this is a LiveURL files request | |
if (!empty($GLOBALS['LIVE_URL']['REQUEST_URI']) && strpos($GLOBALS['LIVE_URL']['REQUEST_URI'], '/live/files/')===0) { | |
// get request info | |
$request=explode('-', $GLOBALS['LIVE_URL']['REQUEST'][0]); | |
if (is_numeric($request[0])) { | |
//query database for files tagged "private" | |
if ($res2=$_LW->dbo->query('select', '1', 'livewhale_files', 'livewhale_files.id='.(int)$request[0])->innerJoin('livewhale_tags2any', 'livewhale_tags2any.id2=livewhale_files.id AND livewhale_tags2any.type="files"')->innerJoin('livewhale_tags', 'livewhale_tags.id=livewhale_tags2any.id1 AND livewhale_tags.title LIKE "%private%"')->firstRow()->run()) { | |
//redirect to authenticated directory | |
die(header('Location: /authenticated-directory/files/'.$request[0])); | |
}; | |
}; | |
}; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment