-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCode.gs
123 lines (111 loc) · 3.89 KB
/
Code.gs
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
function doGet(e) {
if (e.parameters.goto == 'team') {
return HtmlService.createTemplateFromFile('team')
.evaluate()
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.addMetaTag('viewport', 'width=device-width, initial-scale=1');
}
if (e.parameters.goto == 'event') {
return HtmlService.createTemplateFromFile('event')
.evaluate()
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.addMetaTag('viewport', 'width=device-width, initial-scale=1');
}
return HtmlService.createTemplateFromFile('index')
.evaluate()
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.addMetaTag('viewport', 'width=device-width, initial-scale=1');
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
// This function is used to return two array of child folders and child folder's Id , where agrument is Parent Folder's Id
function folderNamesAndIds(parentFolder) {
let folderNames = [];
let folderIds = [];
while (parentFolder.hasNext()) {
let Folder = parentFolder.next();
folderNames.push(Folder.getName());
folderIds.push(Folder.getId());
}
return [folderNames, folderIds]
}
// This code is used for getting folders and displaying Images -----------------------------------------------------
function checkForChildFoldersAndFiles(parentFolderId) {
const parentfiles = DriveApp.getFolderById(parentFolderId).getFiles();
const parentfolders = DriveApp.getFolderById(parentFolderId).getFolders();
let doesParentFolderHaveFiles = false;
if (parentfiles.hasNext()) {
doesParentFolderHaveFiles = true;
}
let [folderNames, folderIds] = folderNamesAndIds(parentfolders);
return [folderNames, doesParentFolderHaveFiles, folderIds, parentFolderId]
}
// function for getting options in Album Dropdown Menu
function yearBtn() {
const sdaWebsiteFolder = DriveApp.getFolderById('127DYBOd4M98t6KNCJeZ9Y6WJB7B5wb_3').getFolders();
let [folderNames, folderIds] = folderNamesAndIds(sdaWebsiteFolder);
let folderList = [];
for (i = 0; i < folderNames.length; i++) {
let list = {
name: folderNames[i],
id: folderIds[i]
};
folderList.push(list);
};
let byName = folderList.slice(0);
byName.sort(function (a, b) {
let x = a.name.toLowerCase();
let y = b.name.toLowerCase();
return x > y ? -1 : x < y ? 1 : 0;
});
for (i = 0; i < byName.length; i++) {
folderNames[i] = byName[i].name;
folderIds[i] = byName[i].id;
};
return [folderNames, folderIds];
}
// Get Event Folders for displaying at home page
function cardsDisplay(FolderId) {
const Folders = DriveApp.getFolderById(FolderId).getFolders();
let [folderNames, folderIds] = folderNamesAndIds(Folders);
return [folderNames, folderIds];
}
function websiteFetch(websiteToFetch) {
var response = UrlFetchApp.fetch(websiteToFetch);
var content = response.getContentText();
return content
}
function getBreadcrumbData(id) {
var x = DriveApp.getFolderById(id);
var name = x.getName();
var id = x.getId();
return [id, name];
}
function sendMail() {
MailApp.sendEmail('[email protected]', 'Entry for SDA site', 'Data has been added to the spreadsheet. The link to the spreadsheet is attached below: https://docs.google.com/spreadsheets/d/1xJ8TyAVEcSm5RtgHW1KOOsb3-vbK3rmyC0eq2uCWZ4U/edit#gid=1155803024');
}
// recaptcha
var secret = INSERT_YOUR_SECRET_HERE;
function verifyCaptcha(formObj) {
var payload = {
'secret': secret,
'response': formObj
}
var url = 'https://www.google.com/recaptcha/api/siteverify';
var resp = UrlFetchApp.fetch(url, {
payload: payload,
method: 'POST'
}).getContentText();
return JSON.parse(resp).success;
}
// Runs reCaptcha and Verifies bot/human
function processForm(obj) {
var isNotBot = verifyCaptcha(obj);
if (!isNotBot) {
return 'You are a robot';
}
sendMail();
return 'Form submitted successfully';
}