-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.gs
334 lines (253 loc) · 9.55 KB
/
settings.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
var settingsArray = getSettings()
// checkSettings(): Verifies settings on the main page and that they are correct and that they aren't empty.
// Return true = good to go; return false = missing
function checkSettings() {
var ui = SpreadsheetApp.getUi() // Grab UI for alerts
if (settingsArray[2][0] == "TRUE" || settingsArray[8][0] == "TRUE") { // If email is checked
if (settingsArray[2][1] == "" || settingsArray[2][2] == "" || settingsArray[2][3] == "" || settingsArray[6][2] == "" || settingsArray[6][3] == "") { // If slots are empty
var result = ui.alert( // Alert
'Error',
'Email settings are incomplete. Please verify email settings and links.',
ui.ButtonSet.OK
)
return false
}
}
if (settingsArray[3][0] == "TRUE") { // If Twitter is checked
if (settingsArray[3][1] == "" || settingsArray[3][2] == "" || settingsArray[3][3] == "" || settingsArray[3][4] == "") {
var result = ui.alert(
'Error',
'Twitter settings are incomplete. Please verify Twitter settings.',
ui.ButtonSet.OK
)
return false
}
}
if (settingsArray[4][0] == "TRUE") { // If Slides is checked
if (settingsArray[4][1] == "" || settingsArray[4][2] == "") {
var result = ui.alert(
'Error',
'Slides settings are incomplete. Please verify Slides settings and links.',
ui.ButtonSet.OK
)
return false
}
}
if (settingsArray[5][0] == "TRUE") { // If image is checked
if (settingsArray[5][1] == "" || settingsArray[6][2] == "" || settingsArray[6][3] == "") {
var result = ui.alert(
'Error',
'Image settings are incomplete. Please verify image settings and links.',
ui.ButtonSet.OK
)
return false
}
}
return true
}
// changeLogo(): Replaces logo on template with "Logo" file in "Icons" folder.
function changeLogo() {
var slide = SlidesApp.openById(settingsArray[6][1]).getSlides()
var folder = DriveApp.getFolderById(settingsArray[6][3])
var image
if (folder.getFilesByName("Logo").hasNext()) {
image = folder.getFilesByName("Logo").next()
} else {
image = folder.getFilesByName("Blank").next()
}
for (var i = 0; i < slide.length; i++) {
slide[i].getImages()[2].replace(image)
}
}
// changeColor(): Edits colors of template with values in spreadsheet.
function changeColor() {
var hex1 = settingsArray[0][0]
var hex2 = settingsArray[0][1]
var textArray1 = [
[5, 7],
[7, 10],
[5],
[7],
[]
]
var textArray2 = [
[6],
[5, 8],
[],
[5],
[5, 6]
]
var slide
var slideNum = [6,4]
for (var x = 0; x < slideNum.length; x++) {
slide = SlidesApp.openById(settingsArray[slideNum[x]][1]).getSlides()
for (var s = 0; s < slide.length; s++) {
try {
slide[s].getShapes()[2].getFill().setSolidFill(hex1)
} catch(error) {
}
for (var i = 0; i < textArray1[s].length; i++) {
slide[s].getShapes()[textArray1[s][i]].getText().getTextStyle().setForegroundColor(hex1)
}
for (var i = 0; i < textArray2[s].length; i++) {
slide[s].getShapes()[textArray2[s][i]].getText().getTextStyle().setForegroundColor(hex2)
}
}
}
}
// resetAutoSheets(): Deletes all automatic sheets
function resetAutoSheets() {
var ui = SpreadsheetApp.getUi()
var spread = SpreadsheetApp.openById(settingsArray[6][0])
var delCur = 2
var final = 2
var result = ui.alert(
'Reset Auto Sheets',
'The following will clear all automated sheets. Are you sure you would like continue?',
ui.ButtonSet.YES_NO
)
if (result == ui.Button.YES){
for (var i = spread.getSheets().length - 1; i > 1; i--){
if (spread.getSheets()[i].getRange(1, 26).getDisplayValue() == "1" && spread.getSheets()[i].getRange(1, 25).getDisplayValue() != "1") {
spread.deleteSheet(spread.getSheets()[i])
}
}
}
}
// resetSheets(): Deletes all sheets
function resetSheets() {
var ui = SpreadsheetApp.getUi()
var spread = SpreadsheetApp.openById(settingsArray[6][0])
var result = ui.alert(
'Reset Sheets',
'The following will clear ALL sheets including custom scores. Are you sure you would like continue?',
ui.ButtonSet.YES_NO
)
if (result == ui.Button.YES) {
for (var i = spread.getSheets().length - 1; i > 1; i--){
spread.deleteSheet(spread.getSheets()[i])
}
}
}
// clearMarked(): Clear all marked checkmarks
function clearMarked() {
var ui = SpreadsheetApp.getUi()
var spread = SpreadsheetApp.openById(settingsArray[6][0])
var templateNum
var array = [
[],
[12, 2],
[14, 1],
[6, 1]
]
var result = ui.alert(
'Clear Marked',
'The following will clear all marked posts in this spreadsheet. Are you sure you would like to continue?',
ui.ButtonSet.YES_NO
)
if (result == ui.Button.YES && spread.getSheets().length > 2) {
for (var i = 2; i < spread.getSheets().length; i++) {
templateNum = parseInt(spread.getSheets()[i].getRange(1, 26).getDisplayValue())
spread.getSheets()[i].getRange(2, array[templateNum][0], 999, array[templateNum][1]).setValue("FALSE")
}
}
resetUpdate(0)
}
// clearPosts(): Deletes all posts made for exporting
function clearPosts() {
var ui = SpreadsheetApp.getUi()
var slide = SlidesApp.openById(settingsArray[6][2])
var result = ui.alert(
'Clear Posts',
'The following will clear all created posts ready for export. Are you sure you would like to continue?',
ui.ButtonSet.YES_NO
)
if (result == ui.Button.YES && slide.getSlides().length > 0) {
for (var i = slide.getSlides().length - 1; i > -1; i--) {
slide.getSlides()[i].remove()
}
}
resetUpdate(1)
}
// autoClearNews(): Deletes all old and expired news
function autoClearNews() {
const MILLS = 1000 * 60 * 60 * 24
var slide = SlidesApp.openById(settingsArray[4][2]).getSlides()
var info
for (var i = slide.length-1; i > -1; i--) {
info = slide[i].getShapes()[0].getTitle()
if (
info.substring(0, 1) == "U" && (new Date(info.substring(1))).getTime() < (new Date()).getTime() - MILLS + MILLS/24*6 ||
info.substring(0, 1) == "R" && (new Date(info.substring(1))).getTime() < (new Date()).getTime() - MILLS*3 ||
info.substring(0, 1) == "A" && (new Date(info.substring(1))).getTime() < (new Date()).getTime() - MILLS*5
)
{
slide[i].remove()
}
}
}
// getSettings(): Returns values from overview sheet into 2D array
function getSettings() {
var sheetArray = SpreadsheetApp.getActive().getSheets()[0].getRange(1, 1, 42, 10).getDisplayValues()
var emailMarked, twitterMarked, slidesMarked, imageMarked
var color1 = sheetArray[14][2]
var color2 = sheetArray[15][2]
var autoMarkScore = sheetArray[18][2]
var autoMarkUpcoming = sheetArray[19][2]
var autoMarkThreshold = sheetArray[20][2]
var autoMarkTime = sheetArray[21][2]
var emailSwitch = sheetArray[25][2]
var emailRecipient = sheetArray[27][2]
var emailTitle = sheetArray[28][2]
var emailBody = sheetArray[29][2]
if (emailSwitch == "TRUE"&& emailRecipient != "" && emailTitle != "" && emailBody != "") {
emailMarked = true
} else {
emailMarked = false
}
var twitterSwitch = sheetArray[25][5]
var twitterConsumer = sheetArray[27][5]
var twitterConsumerSecret = sheetArray[28][5]
var twitterAccess = sheetArray[30][5]
var twitterAccessSecret = sheetArray[31][5]
if (twitterSwitch == "TRUE"&& twitterConsumer != "" && twitterConsumerSecret != "" && twitterAccess != "" && twitterAccessSecret != "") {
twitterMarked = true
} else {
twitterMarked = false
}
var slidesSwitch = sheetArray[25][8]
var slidesTemplateId = sheetArray[40][2].substring(sheetArray[40][2].indexOf("/d/") + 3, sheetArray[40][2].indexOf("/edit"))
var slidesId = sheetArray[39][2].substring(sheetArray[39][2].indexOf("/d/") + 3, sheetArray[39][2].indexOf("/edit"))
var slidesAutoClear = sheetArray[27][8]
if (slidesSwitch == "TRUE"&& slidesTemplateId != "" && slidesId != "") {
slidesMarked = true
} else {
slidesMarked = false
}
var imageSwitch = sheetArray[29][8]
var imageFolderId = sheetArray[41][2].substring(sheetArray[41][2].indexOf("/folders/") + 9, sheetArray[41][2].length)
if (imageSwitch == "TRUE"&& imageFolderId != "") {
imageMarked = true
} else {
imageMarked = false
}
var spreadsheetId = SpreadsheetApp.getActive().getId()
var templateId = sheetArray[35][2].substring(sheetArray[35][2].indexOf("/d/") + 3, sheetArray[35][2].indexOf("/edit"))
var postId = sheetArray[36][2].substring(sheetArray[36][2].indexOf("/d/") + 3, sheetArray[36][2].indexOf("/edit"))
var iconId = sheetArray[37][2].substring(sheetArray[37][2].indexOf("/folders/") + 9, sheetArray[37][2].length)
var backgroundId = sheetArray[38][2].substring(sheetArray[38][2].indexOf("/folders/") + 9, sheetArray[38][2].length)
var masterSwitch = sheetArray[12][9]
var emailTextSwitch = sheetArray[31][8]
var settingsArray = [
[color1, color2],
[autoMarkScore, autoMarkUpcoming, autoMarkThreshold, autoMarkTime],
[emailSwitch, emailRecipient, emailTitle, emailBody],
[twitterSwitch, twitterConsumer, twitterConsumerSecret, twitterAccess, twitterAccessSecret],
[slidesSwitch, slidesTemplateId, slidesId, slidesAutoClear],
[imageSwitch, imageFolderId],
[spreadsheetId, templateId, postId, iconId, backgroundId],
[masterSwitch],
[emailTextSwitch]
]
return settingsArray
}