/** * For folders, will need to add or remove the htaccess rules * Assumptions: * - the folder exists (after write!) * - no one else is trying to put htaccess rules here * - (follows from above) existing htaccess file was put there by this module * @todo Add better support for existing htaccess files */ function onAfterWrite() { parent::onAfterWrite(); if ($this->owner instanceof Folder) { $htaccess = $this->owner->getFullPath() . SecureFileController::get_access_filename(); if ($this->owner->Secured && !file_exists($htaccess)) { file_put_contents($htaccess, $this->htaccessContent()); } elseif (!$this->owner->Secured && file_exists($htaccess)) { unlink($htaccess); } } }
function checkHasHtaccess($folder) { $htaccess_path = BASE_PATH . "/{$folder->Filename}" . SecureFileController::get_access_filename(); if (!file_exists($htaccess_path)) { return false; } $content = file_get_contents($htaccess_path); return $content == singleton('File')->htaccessContent(); }