tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); $core->tpl->addValue('fileAliasURL',array('templateAlias','fileAliasURL')); class templateAlias { public static function fileAliasURL($attr) { global $core, $_ctx; $f = $GLOBALS['core']->tpl->getFilters($attr); return 'blog->url.$core->url->getBase("filesalias")."/".$_ctx->filealias->filesalias_url').'; ?>'; } } class urlFilesAlias extends dcUrlHandlers { public static function alias($args) { $_ctx =& $GLOBALS['_ctx']; $core =& $GLOBALS['core']; $delete = false; $_ctx->filealias = $core->filealias->getAlias($args); if ($_ctx->filealias->isEmpty()) { self::p404(); } if ($_ctx->filealias->filesalias_disposable) { $delete = true; } if ($_ctx->filealias->filesalias_password) { # Check for match if (!empty($_POST['filepassword']) && $_POST['filepassword'] == $_ctx->filealias->filesalias_password) { self::servefile($_ctx->filealias->filesalias_destination,$args,$delete); } else { self::serveDocument('file-password-form.html','text/html',false); return; } } else { self::servefile($_ctx->filealias->filesalias_destination,$args,$delete); } } public static function servefile($target,$alias,$delete=false) { $core =& $GLOBALS['core']; $a= new aliasMedia($core); $media = $a->getMediaId($target); if (empty($media)) { self::p404(); } $file = $core->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) { $core->filealias->deleteAlias($alias); } return; } }