예제 #1
0
        protected void ExportWord_Click(object sender, EventArgs e)
        {
            var sbContent = new StringBuilder();
            var list      = DataProvider.KeywordDao.GetKeywordInfoList();

            if (list.Count <= 0)
            {
                return;
            }

            foreach (var keywordInfo in list)
            {
                sbContent.Append(keywordInfo.Keyword);
                if (!string.IsNullOrEmpty(keywordInfo.Alternative))
                {
                    sbContent.Append("|");
                    sbContent.Append(keywordInfo.Alternative);
                }
                sbContent.Append(",");
            }
            if (sbContent.Length > 0)
            {
                sbContent.Length -= 1;
            }

            var filePath = PathUtils.GetTemporaryFilesPath("敏感词.txt");

            FileUtils.DeleteFileIfExists(filePath);
            FileUtils.WriteText(filePath, ECharset.utf_8, sbContent.ToString());
            PageUtils.Download(Page.Response, filePath);
        }
예제 #2
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("siteId");

            var specialId = AuthRequest.GetQueryInt("specialId");
            var keyword   = AuthRequest.GetQueryString("keyword");

            if (IsPostBack)
            {
                return;
            }

            VerifySitePermissions(ConfigManager.WebSitePermissions.Template);

            TbKeyword.Text = keyword;

            if (specialId > 0)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["delete"]))
                {
                    var specialInfo = SpecialManager.DeleteSpecialInfo(SiteId, specialId);

                    AuthRequest.AddSiteLog(SiteId,
                                           "删除专题",
                                           $"专题名称:{specialInfo.Title}");

                    SuccessDeleteMessage();
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["download"]))
                {
                    var specialInfo   = SpecialManager.GetSpecialInfo(SiteId, specialId);
                    var directoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, specialInfo.Url);
                    var zipFilePath   = SpecialManager.GetSpecialZipFilePath(directoryPath);
                    PageUtils.Download(Response, zipFilePath, $"{specialInfo.Title}.zip");
                    return;
                }
            }

            RptContents.DataSource = string.IsNullOrEmpty(keyword)
                ? DataProvider.SpecialDao.GetSpecialInfoList(SiteId)
                : DataProvider.SpecialDao.GetSpecialInfoList(SiteId, keyword);
            RptContents.ItemDataBound += RptContents_ItemDataBound;
            RptContents.DataBind();

            BtnAdd.Attributes.Add("onclick", ModalSpecialAdd.GetOpenWindowString(SiteId));
        }
        public void Main()
        {
            try
            {
                var request = new AuthenticatedRequest();

                if (!string.IsNullOrEmpty(request.GetQueryString("siteId")) && !string.IsNullOrEmpty(request.GetQueryString("fileUrl")) && string.IsNullOrEmpty(request.GetQueryString("contentId")))
                {
                    var siteId  = request.GetQueryInt("siteId");
                    var fileUrl = TranslateUtils.DecryptStringBySecretKey(request.GetQueryString("fileUrl"));

                    if (PageUtils.IsProtocolUrl(fileUrl))
                    {
                        PageUtils.Redirect(fileUrl);
                        return;
                    }

                    var siteInfo = SiteManager.GetSiteInfo(siteId);
                    var filePath = PathUtility.MapPath(siteInfo, fileUrl);
                    var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath));
                    if (EFileSystemTypeUtils.IsDownload(fileType))
                    {
                        if (FileUtils.IsFileExists(filePath))
                        {
                            PageUtils.Download(HttpContext.Current.Response, filePath);
                            return;
                        }
                    }
                    else
                    {
                        PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false));
                        return;
                    }
                }
                else if (!string.IsNullOrEmpty(request.GetQueryString("filePath")))
                {
                    var filePath = TranslateUtils.DecryptStringBySecretKey(request.GetQueryString("filePath"));
                    var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath));
                    if (EFileSystemTypeUtils.IsDownload(fileType))
                    {
                        if (FileUtils.IsFileExists(filePath))
                        {
                            PageUtils.Download(HttpContext.Current.Response, filePath);
                            return;
                        }
                    }
                    else
                    {
                        var fileUrl = PageUtils.GetRootUrlByPhysicalPath(filePath);
                        PageUtils.Redirect(PageUtils.ParseNavigationUrl(fileUrl));
                        return;
                    }
                }
                else if (!string.IsNullOrEmpty(request.GetQueryString("siteId")) && !string.IsNullOrEmpty(request.GetQueryString("channelId")) && !string.IsNullOrEmpty(request.GetQueryString("contentId")) && !string.IsNullOrEmpty(request.GetQueryString("fileUrl")))
                {
                    var siteId      = request.GetQueryInt("siteId");
                    var channelId   = request.GetQueryInt("channelId");
                    var contentId   = request.GetQueryInt("contentId");
                    var fileUrl     = TranslateUtils.DecryptStringBySecretKey(request.GetQueryString("fileUrl"));
                    var siteInfo    = SiteManager.GetSiteInfo(siteId);
                    var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);

                    DataProvider.ContentDao.AddDownloads(siteId, ChannelManager.GetTableName(siteInfo, channelInfo), channelId, contentId);

                    if (!string.IsNullOrEmpty(contentInfo?.GetString(BackgroundContentAttribute.FileUrl)))
                    {
                        if (PageUtils.IsProtocolUrl(fileUrl))
                        {
                            PageUtils.Redirect(fileUrl);
                            return;
                        }

                        var filePath = PathUtility.MapPath(siteInfo, fileUrl, true);
                        var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath));
                        if (EFileSystemTypeUtils.IsDownload(fileType))
                        {
                            if (FileUtils.IsFileExists(filePath))
                            {
                                PageUtils.Download(HttpContext.Current.Response, filePath);
                                return;
                            }
                        }
                        else
                        {
                            PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false));
                            return;
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }

            HttpContext.Current.Response.Write("下载失败,不存在此文件!");
        }
        public void Main()
        {
            var isSuccess = false;

            try
            {
                var request = new AuthRequest();

                if (!string.IsNullOrEmpty(request.GetQueryString("siteId")) && !string.IsNullOrEmpty(request.GetQueryString("fileUrl")) && string.IsNullOrEmpty(request.GetQueryString("contentId")))
                {
                    var siteId  = request.GetQueryInt("siteId");
                    var fileUrl = TranslateUtils.DecryptStringBySecretKey(request.GetQueryString("fileUrl"));

                    if (PageUtils.IsProtocolUrl(fileUrl))
                    {
                        isSuccess = true;
                        PageUtils.Redirect(fileUrl);
                    }
                    else
                    {
                        var siteInfo = SiteManager.GetSiteInfo(siteId);
                        var filePath = PathUtility.MapPath(siteInfo, fileUrl);
                        var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath));
                        if (EFileSystemTypeUtils.IsDownload(fileType))
                        {
                            if (FileUtils.IsFileExists(filePath))
                            {
                                isSuccess = true;
                                PageUtils.Download(HttpContext.Current.Response, filePath);
                            }
                        }
                        else
                        {
                            isSuccess = true;
                            PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false));
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(request.GetQueryString("filePath")))
                {
                    var filePath = TranslateUtils.DecryptStringBySecretKey(request.GetQueryString("filePath"));
                    var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath));
                    if (EFileSystemTypeUtils.IsDownload(fileType))
                    {
                        if (FileUtils.IsFileExists(filePath))
                        {
                            isSuccess = true;
                            PageUtils.Download(HttpContext.Current.Response, filePath);
                        }
                    }
                    else
                    {
                        isSuccess = true;
                        var fileUrl = PageUtils.GetRootUrlByPhysicalPath(filePath);
                        PageUtils.Redirect(PageUtils.ParseNavigationUrl(fileUrl));
                    }
                }
                else if (!string.IsNullOrEmpty(request.GetQueryString("siteId")) && !string.IsNullOrEmpty(request.GetQueryString("channelId")) && !string.IsNullOrEmpty(request.GetQueryString("contentId")) && !string.IsNullOrEmpty(request.GetQueryString("fileUrl")))
                {
                    var siteId      = request.GetQueryInt("siteId");
                    var channelId   = request.GetQueryInt("channelId");
                    var contentId   = request.GetQueryInt("contentId");
                    var fileUrl     = TranslateUtils.DecryptStringBySecretKey(request.GetQueryString("fileUrl"));
                    var siteInfo    = SiteManager.GetSiteInfo(siteId);
                    var nodeInfo    = ChannelManager.GetChannelInfo(siteId, channelId);
                    var tableName   = ChannelManager.GetTableName(siteInfo, nodeInfo);
                    var contentInfo = DataProvider.ContentDao.GetContentInfo(tableName, contentId);

                    if (!string.IsNullOrEmpty(contentInfo?.GetString(BackgroundContentAttribute.FileUrl)))
                    {
                        //string fileUrl = contentInfo.GetString(BackgroundContentAttribute.FileUrl);
                        if (siteInfo.Additional.IsCountDownload)
                        {
                            CountManager.AddCount(tableName, contentId.ToString(), ECountType.Download);
                        }

                        if (PageUtils.IsProtocolUrl(fileUrl))
                        {
                            isSuccess = true;
                            PageUtils.Redirect(fileUrl);
                        }
                        else
                        {
                            var filePath = PathUtility.MapPath(siteInfo, fileUrl, true);
                            var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath));
                            if (EFileSystemTypeUtils.IsDownload(fileType))
                            {
                                if (FileUtils.IsFileExists(filePath))
                                {
                                    isSuccess = true;
                                    PageUtils.Download(HttpContext.Current.Response, filePath);
                                }
                            }
                            else
                            {
                                isSuccess = true;
                                PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false));
                            }
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }
            if (!isSuccess)
            {
                HttpContext.Current.Response.Write("下载失败,不存在此文件!");
            }
        }