Skip to content

Commit a2e62ef

Browse files
committed
Placeholder images for various file extensions in file manager
1 parent be08f78 commit a2e62ef

10 files changed

Lines changed: 62 additions & 3 deletions

File tree

BlogEngine/BlogEngine.Core/Services/FileSystem/Common.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,48 @@ public class FileInstance
2121
public string FileSize { get; set; }
2222
public FileType FileType { get; set; }
2323
public string FullPath { get; set; }
24+
/// <summary>
25+
/// Image assosiated with file extension
26+
/// </summary>
27+
public string ImgPlaceholder
28+
{
29+
get
30+
{
31+
if(FileType == FileType.File)
32+
{
33+
return getPlaceholder(Name);
34+
}
35+
return string.Empty;
36+
}
37+
}
38+
39+
static string getPlaceholder(string name)
40+
{
41+
var file = name.ToLower().Trim();
42+
43+
if (file.EndsWith(".zip") || file.EndsWith(".gzip") || file.EndsWith(".7zip") || file.EndsWith(".rar"))
44+
{
45+
return "zip.png";
46+
}
47+
if (file.EndsWith(".doc") || file.EndsWith(".docx"))
48+
{
49+
return "doc.png";
50+
}
51+
if (file.EndsWith(".xls") || file.EndsWith(".xlsx"))
52+
{
53+
return "xls.png";
54+
}
55+
if (file.EndsWith(".pdf"))
56+
{
57+
return "pdf.png";
58+
}
59+
if (file.EndsWith(".txt"))
60+
{
61+
return "txt.png";
62+
}
63+
64+
return "new.png";
65+
}
2466
}
2567

2668
public enum FileType

BlogEngine/BlogEngine.NET/AppCode/Api/UploadController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public HttpResponseMessage Post(string action, string dirPath = "")
4242
action = "file";
4343
}
4444

45-
var dir = BlogService.GetDirectory(dirName);
45+
var dir = new BlogEngine.Core.FileSystem.Directory();
4646
var retUrl = "";
4747

4848
if (action == "import")
@@ -74,6 +74,7 @@ public HttpResponseMessage Post(string action, string dirPath = "")
7474
{
7575
if (Security.IsAuthorizedTo(Rights.EditOwnPosts))
7676
{
77+
dir = BlogService.GetDirectory(dirName);
7778
var uploaded = BlogService.UploadFile(file.InputStream, fileName, dir, true);
7879
return Request.CreateResponse(HttpStatusCode.Created, uploaded.AsImage.ImageUrl);
7980
}
@@ -82,6 +83,7 @@ public HttpResponseMessage Post(string action, string dirPath = "")
8283
{
8384
if (Security.IsAuthorizedTo(Rights.EditOwnPosts))
8485
{
86+
dir = BlogService.GetDirectory(dirName);
8587
var uploaded = BlogService.UploadFile(file.InputStream, fileName, dir, true);
8688
retUrl = uploaded.FileDownloadPath + "|" + fileName + " (" + BytesToString(uploaded.FileSize) + ")";
8789
return Request.CreateResponse(HttpStatusCode.Created, retUrl);

BlogEngine/BlogEngine.NET/BlogEngine.NET.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,13 @@
568568
<Content Include="Content\images\blog\flags\zm.png" />
569569
<Content Include="Content\images\blog\flags\zw.png" />
570570
<Content Include="Content\images\blog\pingback.png" />
571+
<Content Include="Content\images\blog\placeholders\doc.png" />
571572
<Content Include="Content\images\blog\placeholders\folder.png" />
572573
<Content Include="Content\images\blog\placeholders\folder_back.png" />
574+
<Content Include="Content\images\blog\placeholders\new.png" />
575+
<Content Include="Content\images\blog\placeholders\pdf.png" />
576+
<Content Include="Content\images\blog\placeholders\txt.png" />
577+
<Content Include="Content\images\blog\placeholders\xls.png" />
573578
<Content Include="Content\images\blog\placeholders\zip.png" />
574579
<Content Include="Content\images\blog\xfn\colleague.gif" />
575580
<Content Include="Content\images\blog\xfn\colleagueMet.gif" />
7.1 KB
Loading
7.93 KB
Loading
7.49 KB
Loading
4.55 KB
Loading
5.35 KB
Loading
2.76 KB
Loading

BlogEngine/BlogEngine.NET/admin/filemanager.cshtml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@using System.Web.Optimization
22
@using BlogEngine.Core
3+
@using BlogEngine.Core.FileSystem
34
<!DOCTYPE html>
45
@{
56
if (!Security.IsAuthorizedTo(Rights.EditOwnPosts))
@@ -11,6 +12,15 @@
1112
var id = Request["id"];
1213
var returnUrl = Request["return"];
1314
if (string.IsNullOrEmpty(returnUrl)) { returnUrl = Utils.RelativeWebRoot + "admin/#/content"; }
15+
var imgHandler = "image.axd?picture=";
16+
if (string.IsNullOrEmpty(Blog.CurrentInstance.StorageContainerName))
17+
{
18+
imgHandler = Blog.CurrentInstance.RelativeWebRoot + imgHandler;
19+
}
20+
else
21+
{
22+
imgHandler = Blog.CurrentInstance.RelativeWebRoot + Blog.CurrentInstance.StorageContainerName + "/" + imgHandler;
23+
}
1424
}
1525
<html data-ng-app="blogAdmin">
1626
<head>
@@ -112,10 +122,10 @@
112122
<img ng-src="{{root}}Content/images/blog/placeholders/folder_back.png" />
113123
</a>
114124
<a ng-if="item.FileType === 1" title="{{item.Name}}" href="" ng-click="insertFile(item)">
115-
<img ng-src="{{root}}Content/images/blog/placeholders/zip.png" />
125+
<img ng-src="{{root}}Content/images/blog/placeholders/{{item.ImgPlaceholder}}" />
116126
</a>
117127
<a ng-if="item.FileType === 2" title="{{item.Name}}" href="" ng-click="insertFile(item)">
118-
<img ng-src="{{root}}@Blog.CurrentInstance.StorageContainerName/image.axd?picture={{item.FullPath}}" />
128+
<img ng-src="@imgHandler{{item.FullPath}}" />
119129
</a>
120130
</div>
121131
<div class="file-card-lbl">

0 commit comments

Comments
 (0)