Exemplo n.º 1
0
        /**
         * 显示文章缩略图,顺序为:文章第一张图 -> 随机获取
         *
         * @return
         */

        public string show_thumb(Contents contents)
        {
            if (null == contents)
            {
                return("");
            }
            Set_current_article(contents);
            if (StringKit.IsNotBlank(contents.ThumbImg))
            {
                string newFileName     = IBlogsUtils.getFileName(contents.ThumbImg);
                string thumbnailImgUrl = (contents.ThumbImg).Replace(newFileName, "thumbnail_" + newFileName);
                return(thumbnailImgUrl);
            }
            string content = article(contents.Content);
            string img     = IBlogsUtils.show_thumb(content);

            if (StringKit.IsNotBlank(img))
            {
                return(img);
            }
            int?cid  = contents.Id;
            int?size = cid % 20;

            size = size == 0 ? 1 : size;
            return("/templates/themes/default/static/img/rand/" + size + ".jpg");
        }
Exemplo n.º 2
0
        private bool InitOptions()
        {
            _optionService.saveOption("allow_install", "false", "是否允许重新安装博客");
            _optionService.saveOption("allow_comment_audit", "true", "评论需要审核");
            _optionService.saveOption("ite_keywords", "博客系统,asp.net core,iBlogs");
            _optionService.saveOption("site_description", "博客系统,asp.net core,iBlogs");
            var siteUrl = IBlogsUtils.buildURL(_param.SiteUrl);

            _optionService.saveOption("site_title", _param.SiteTitle);
            _optionService.saveOption("site_url", siteUrl);
            return(true);
        }
Exemplo n.º 3
0
        public void Delete(int id)
        {
            var attach = _repository.FirstOrDefault(id);

            if (attach == null)
            {
                return;
            }
            var filePath          = _env.WebRootPath + attach.FKey;
            var newFileName       = IBlogsUtils.getFileName(attach.FKey);
            var thumbnailFilePath = _env.WebRootPath + attach.FKey.Replace(newFileName, "thumbnail_" + newFileName);

            _repository.Delete(attach);
            _repository.SaveChanges();
            File.Delete(filePath);
            File.Delete(thumbnailFilePath);
        }
Exemplo n.º 4
0
        /**
         * 截取文章摘要
         *
         * @param value 文章内容
         * @param len   要截取文字的个数
         * @return
         */

        public string intro(string value, int len)
        {
            int pos = value.IndexOf("<!--more-->");

            if (pos != -1)
            {
                string html = value.Substring(0, pos);
                return(IBlogsUtils.htmlToText(Markdown.ToHtml(html)));
            }
            else
            {
                string text = IBlogsUtils.htmlToText(Markdown.ToHtml(value));
                if (text.Length > len)
                {
                    return(text.Substring(0, len));
                }
                return(text);
            }
        }
Exemplo n.º 5
0
        public async Task <ApiResponse <List <Attachment> > > UploadAsync(List <IFormFile> files)
        {
            //log.info("UPLOAD DIR = {}", TaleUtils.UP_DIR);

            var users = _userService.CurrentUsers;
            var uid   = users.Uid;
            List <Attachment> errorFiles = new List <Attachment>();
            List <Attachment> urls       = new List <Attachment>();

            var fileItems = HttpContext.Request.Form.Files;

            if (null == fileItems || fileItems.Count == 0)
            {
                return(ApiResponse <List <Attachment> > .Fail("请选择文件上传"));
            }

            foreach (var fileItem in fileItems)
            {
                string fname = fileItem.FileName;
                if ((fileItem.Length / 1024) <= iBlogsConst.MAX_FILE_SIZE)
                {
                    var fkey = IBlogsUtils.getFileKey(fname, _env.WebRootPath);

                    var ftype    = fileItem.ContentType.Contains("image") ? Types.IMAGE : Types.FILE;
                    var filePath = _env.WebRootPath + fkey;

                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await fileItem.CopyToAsync(stream);
                    }
                    if (IBlogsUtils.isImage(filePath))
                    {
                        var newFileName       = IBlogsUtils.getFileName(fkey);
                        var thumbnailFilePath = _env.WebRootPath + fkey.Replace(newFileName, "thumbnail_" + newFileName);
                        IBlogsUtils.cutCenterImage(_env.WebRootPath + fkey, thumbnailFilePath, 270, 380);
                    }

                    Attachment attachment = new Attachment();
                    attachment.FName    = fname;
                    attachment.AuthorId = uid;
                    attachment.FKey     = fkey;
                    attachment.FType    = ftype;
                    attachment.Created  = DateTime.Now.ToUnixTimestamp();
                    if (await _attachService.Save(attachment))
                    {
                        urls.Add(attachment);
                    }
                    else
                    {
                        errorFiles.Add(attachment);
                    }
                }
                else
                {
                    Attachment attachment = new Attachment();
                    attachment.FName = fname;
                    errorFiles.Add(attachment);
                }
            }

            if (errorFiles.Count > 0)
            {
                return(ApiResponse <List <Attachment> > .Fail().SetPayload(errorFiles));
            }
            return(ApiResponse <List <Attachment> > .Ok(urls));
        }
Exemplo n.º 6
0
 public static string PwdMd5(string userName, string password)
 {
     return(IBlogsUtils.md5(userName, password));
 }
Exemplo n.º 7
0
 public void PwdMd5()
 {
     Password = IBlogsUtils.md5(Username, Password);
 }