tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates'); dcCore::app()->tpl->addValue('fileAliasURL', ['templateAlias','fileAliasURL']); class templateAlias { public static function fileAliasURL($attr) { $f = dcCore::app()->tpl->getFilters($attr); return 'blog->url.dcCore::app()->url->getBase("filesalias")."/".dcCore::app()->ctx->filealias->filesalias_url') . '; ?>'; } } class urlFilesAlias extends dcUrlHandlers { public static function alias($args) { $delete = false; dcCore::app()->ctx->__set('filealias', dcCore::app()->__get('filealias')->getAlias($args)); if (dcCore::app()->ctx->__get('filealias')->isEmpty()) { self::p404(); } if (dcCore::app()->ctx->__get('filealias')->filesalias_disposable) { $delete = true; } if (dcCore::app()->ctx->__get('filealias')->filesalias_password) { # Check for match if (!empty($_POST['filepassword']) && $_POST['filepassword'] == dcCore::app()->ctx->__get('filealias')->filesalias_password) { self::servefile(dcCore::app()->ctx->__get('filealias')->filesalias_destination, $args, $delete); } else { self::serveDocument('file-password-form.html', 'text/html', false); return; } } else { self::servefile(dcCore::app()->ctx->__get('filealias')->filesalias_destination, $args, $delete); } } public static function servefile($target, $alias, $delete = false) { $a = new aliasMedia(); $media = $a->getMediaId($target); if (empty($media)) { self::p404(); } $file = dcCore::app()->media->getFile($media); if (empty($file->file)) { self::p404(); } header('Content-type: ' . $file->type); header('Content-Length: ' . $file->size); header('Content-Disposition: attachment; filename="' . $file->basename . '"'); if (ob_get_length() > 0) { ob_end_clean(); } flush(); readfile($file->file); if ($delete) { dcCore::app()->__get('filealias')->deleteAlias($alias); } } }