forked from foundeo/cfdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openimage.cfm
140 lines (126 loc) · 4.3 KB
/
openimage.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<cfscript>
param name="url.name" default="";
filepath = "/assets/img/opengraph/";
data = {
name:"CF Docs",
type:"All",
description:"UltraFast CFML Documentation Reference.",
syntax:"",
member:"",
script:"",
engines:{}
}
url.name = lcase(ReReplace(url.name, "[^a-zA-Z0-9_-]", "", "ALL"));
if(FileExists(ExpandPath("./data/en/#url.name#.json"))){
docsData = DeserializeJSON( FileRead(ExpandPath("./data/en/#url.name#.json")));
filename = "#url.name#.jpg";
//dump(docsData);
structAppend(data,docsData,true);
urlPath = '/' & url.name;
} else if (FileExists(ExpandPath("./guides/en/#url.name#.md"))) {
filename = "#url.name#.jpg";
urlPath = '/' & url.name;
md = listFirst(trim(fileRead(ExpandPath("./guides/en/#url.name#.md"))), chr(13)&chr(10));
if (left(md, 1) == "##") {
data.name = trim(replace(md, "##", "", "ALL"));
} else {
data.name = replace(url.name, "-", " ", "ALL") & " Guide";
}
data.description = "CFML Reference Guide";
} else {
location(url="/assets/img/cfdocs-default-og.jpg", addtoken=false);
abort;
}
if(FileExists( ExpandPath(filepath & filename) )){
location(url=filepath & filename, addtoken=false);
}
vPos = 55;
hPos = 30;
maxlength = 60;
img=imageNew("",512,256,"RGB","##fafafa");
img.setAntialiasing("on");
//Write Tag/Function Name
style={size="35", font="DejaVu Sans"};
style2={size="15", font="DejaVu Sans"};
style4={size="12", font="DejaVu Sans"};
img.setDrawingColor("##333333")
img.DrawText(data.name,hPos,vPos,style);
vPos += 20;
img.setDrawingColor("##c7254e")
if(data.keyExists('returns'))img.DrawText("return <#data.returns#>;" ,hPos,vPos,style4);
img.setDrawingColor("##333333")
//write function/tag description
vPos += 25;
img.DrawText(mid(data.description,1,maxlength),hPos,vPos,style2);
vPos += 20;
if(len(data.description) > maxlength){
secondLine = mid(data.description,maxlength+1,maxlength);
if(len(data.description) > maxlength * 2) secondLine = trim(mid(data.description,maxlength+1,(maxlength-3))) & '...';
img.DrawText(secondLine,hPos,vPos,style2);
vPos += 20;
}
if(len(data.syntax)){
//Write tag syntax
img.setDrawingColor("##c7254e")
vPos += 10;
if(len(data.syntax) > maxlength) data.syntax = mid(data.syntax,1,maxlength-3) & "..."
img.DrawText('## ' & data.syntax,hPos,vPos,style2);
}
if(len(data.script)){
//Write script syntax
img.setDrawingColor("##c7254e")
vPos += 25;
if(len(data.script) > maxlength) data.script = mid(data.script,1,maxlength-3) & "..."
img.DrawText(data.script,hPos,vPos,style2);
}
if(len(data.member)){
//Write script syntax
img.setDrawingColor("##c7254e")
vPos += 25;
if(len(data.member) > maxlength) data.member = mid(data.member,1,maxlength-3) & "..."
img.DrawText(data.member,hPos,vPos,style2);
}
//draw dividing line
img.setDrawingColor("##cccccc")
vPos += 20;
img.DrawRect(hPos,vPos,384,2,true);
vPos += 25;
img.setDrawingColor("##3dbc9c")
img.DrawRect(hPos,vPos-16,20,20,true);
//show url and site name
img.setDrawingColor("##ffffff")
img.DrawText(decodeforhtml("CF"),hPos+1,vPos,style2);
img.setDrawingColor("##444444")
img.DrawText(decodeforhtml("Docs • cfdocs.org#urlPath#"),hPos+24,vPos,style2);
style3={size="11"};
//Blue Dragon Engine Support
if(data.engines.keyExists('openbd')){
img.setDrawingColor("##2fa5d7");
img.drawRect(360,15,23,16,true);
img.setDrawingColor("##ffffff")
img.DrawText("BD",365,27,style3);
}
//Lucee Engine Support
if(data.engines.keyExists('lucee')){
img.setDrawingColor("##449caf");
img.drawRect(388,15,38,16,true);
img.setDrawingColor("##ffffff")
img.DrawText("Lucee",393,27,style3);
}
//ColdFusion Engine Support
if(data.engines.keyExists('coldfusion')){
cfversion = data.engines.coldfusion.minimum_version;
img.setDrawingColor("##006699");
if (len(cfversion)) { cfversion &= "+" }
cfengineboxsize = ((len(cfversion))* 7) + 22;
img.drawRect(432,15,cfengineboxsize,16,true);
img.setDrawingColor("##ffffff")
img.DrawText("CF" & cfversion,436,27,style3);
}
//Draw bottom green border
img.setDrawingColor("##3dbc9c")
img.DrawRect(0,240,512,16,true);
if(!DirectoryExists(ExpandPath(filepath))) DirectoryCreate(ExpandPath(filepath));
ImageWrite(img,ExpandPath(filepath & filename));
cfcontent( reset="true", variable="#toBinary(toBase64(img))#", type="image/jpg");
</cfscript>