Skip to content

Instantly share code, notes, and snippets.

@skerbis
Forked from IngoWinter/.htaccess
Created January 16, 2018 21:49
Show Gist options
  • Save skerbis/371056e55502631cb052c264122b3525 to your computer and use it in GitHub Desktop.
Save skerbis/371056e55502631cb052c264122b3525 to your computer and use it in GitHub Desktop.
auth media für ycom
RewriteRule ^/?media/(.*)$ /index.php?ycom_file=$1 [L]
# RewriteRule ^/?media/(.*\.(pdf|doc|zip))$ /index.php?ycom_file=$1 [L]
<?php
function ycom_check_fileperm($filename, $do_ycom_login = false)
{
// zu schuetzende mediacats, bitte nach bedarf anpassen
$mediacats2protect = [14, 15];
// eltern mediacat der datei holen
$media = rex_media::get($filename);
$mediacat2check = $media->getCategoryId();
$mediacat = $media->getCategory();
if (is_object($mediacat) && count($mediacat->getPathAsArray()))
{
$mediacat2check = $mediacat->getPathAsArray()[0];
}
// datei ist nicht zu schuetzen
if (!in_array($mediacat2check, $mediacats2protect))
{
return true;
}
// bei aufruf ueber media manager ycom nutzer einloggen
if ($do_ycom_login)
{
rex_ycom::addTable('rex_ycom_user');
rex_yform_manager_dataset::setModelClass('rex_ycom_user', rex_ycom_user::class);
$auth = rex_ycom_auth::login([]);
}
$ycom_user = rex_ycom_auth::getUser();
if ($ycom_user)
{
// hier ggfs weitere abfragen
return true;
}
return false;
}
// check fileperm fuer direkte dateiaufrufe
rex_extension::register('FE_OUTPUT', function () {
$filename = rex_get('ycom_file', 'string');
if ($filename && file_exists(rex_path::media($filename)))
{
if (!ycom_check_fileperm($filename))
{
rex_redirect(rex_plugin::get('ycom', 'auth')->getConfig('article_id_jump_denied'));
}
$managed_media = new rex_managed_media(rex_path::media($filename));
(new rex_media_manager($managed_media))->sendMedia();
}
});
// check fileperm fuer media manager dateiaufrufe
$filename = rex_get('rex_media_file', 'string');
if ($filename && file_exists(rex_path::media($filename)))
{
if (!ycom_check_fileperm($filename, true))
{
header('HTTP/1.1 403 Forbidden');
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment