-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
414 lines (307 loc) · 10.9 KB
/
index.php
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://ogp.me/ns/fb#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Trump Bot, Nasty Women, Eric Medine, Twitter API Fetcher" />
<meta name="author" content="Trump Bot" />
<meta property="og:image" content="http://ericmedine.com/TrumpBot/images/preview_image.png" />
<title>Trumpbot</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.1.6.1.min.js"></script>
<script src="js/processing.min.js"></script>
<!-- <script type="text/javascript" src="js/canvassaver.js"></script> -->
<script type="text/javascript">
///// COMMUNICATE WITH PROCESSING
var procElem;
var frameIndex = 0; /// this gets reset every time we do a tweet
var tweetCaption = "";
function startSketch() {
switchSketchState(true);
}
function stopSketch() {
switchSketchState(false);
}
function switchSketchState(on) {
if (!procElem) {
procElem = Processing.getInstanceById('sketch');
console.log("THERE IS PROCESSING");
}
}
///////////// for lip synching animation ///////////////
function sendTextToSketch(t){
try{
var tString = t.replace(/<(?:.|\n)*?>/gm, '');
console.log("send: " + tString);
procElem = Processing.getInstanceById('sketch');
procElem.addText(tString);
if (!procElem) {
console.log("error finding processing element");
}
} catch(e){
console.log("error sending text");
}
}
/// tweets
function sendTweetToSketch(t, n, u){
var tString = "";
var uString = "";
try{
tString = t.replace(/<(?:.|\n)*?>/gm, '');
uString = u.replace(/<(?:.|\n)*?>/gm, '');
uString = uString.replace(/\s+/g, ' ').trim();
uString = uString.replace(/\n/g," ");
/// get rid of the username and keep the @name
uString = uString.substring(uString.indexOf("@") + 1);
uString = "@" + uString;
/// var dString = d.replace(/<(?:.|\n)*?>/gm, '');
/// WE SHOULD SEND THE USER NAME ALSO /////
if(uString === "@saysrealtrump"){
/// makes sure not replying to myself
} else {
procElem = Processing.getInstanceById('sketch');
procElem.addTweet(tString, "RT " + uString + " says ");
console.log("from: " + uString + " says: " + tString);
if (!procElem) {
console.log("error finding processing element");
}
}
} catch(e){
console.log("error sending tweet: " + e);
}
}
/////////// LISTEN TO PROCESSING /////////////////////////////
function reDoSearch(){
console.log("I hear you");
}
/// save single frame from Processing
function saveCurFrame(findex, tweet){
frameIndex = findex;
tweetCaption = tweet;
createCollage();
}
function saveGifFromFrames(tweet){
console.log("save gif");
tweetCaption = tweet;
createGif("../uploads", randomString(10, "a")); ///// pass it the correct folder name
}
function randomString(len, an){
an = an&&an.toLowerCase();
var str="", i=0, min=an=="a"?10:0, max=an=="n"?10:62;
for(;i++<len;){
var r = Math.random()*(max-min)+min <<0;
str += String.fromCharCode(r+=r>9?r<36?55:61:48);
}
return str;
}
var bound = false;
function bindJavascript() {
var pjs = Processing.getInstanceById('sketch');
if(pjs!=null) {
pjs.bindJavascript(this);
bound = true;
}
if(!bound) setTimeout(bindJavascript, 250);
}
bindJavascript();
</script>
</head>
<body>
<!--
<a href="#" id="SaveGif" >SaveGif</a>
<br><br>
-->
<div id="content-main" align="center">
<canvas id="sketch" data-processing-sources="main/main.pde" width="400" height="300"></canvas>
</div>
<br><br>
<div id="content-buffer">
<canvas id="buffercanvas" width="400" height="300"></canvas>
</div>
<!-- extra canvas for drawing -->
<!--
<a href="#" id="nav">Load tweets @shitTrumpSays</a>
<a href="#" id="startText">Speak!</a>
-->
<div id="example4"></div>
<!-- this hidden form uploads the image to the server -->
<!--
<input type="text" id="textEntry" name="textEntry" value="I have tiny hands"/><br>
-->
<script type="text/javascript" src="js/twitterFetcher.js"></script>
<script type="text/javascript" src="js/twitterConsole.js"></script>
<!-- <script type="text/javascript" src="js/imageHandling.js"></script> -->
<script>
var tweetCaption = ""; /// default tweet caption
$( "#SaveGif" ).click(function() {
console.log("save gif");
/// createGif("../uploads", randomString(10, "a")); ///// pass it the correct file name
saveGifFromFrames("CLICK TO SAVE");
// saveFrameCollage();
});
////////////////////////////////////////////
//////////// SAVE IMAGE TO SERVER ////////
///////////////////////////////////////////
function createCollage(){
// console.log("SAVE IMAGE");
var src = document.getElementById('sketch');
var ctxsrc = src.getContext('2d');
var can1 = document.createElement('canvas');
can1.setAttribute('width', '400')
can1.setAttribute('height', '300');
can1.id = "foregroundImage";
var ctx1 = can1.getContext('2d');
ctx1.drawImage(src, 0, 0 );
var can2 = document.createElement('canvas');
can2.setAttribute('width', '400')
can2.setAttribute('height', '300');
can2.id = "backgroundImage";
$('#MergeCanvas').focus();
var context2 = can2.getContext('2d');
make_base(can1, can2);
function make_base(can1, can2)
{
$("#MergeCanvas").attr("tabindex",-1).focus();
base_image = new Image();
base_image.src = "images/background_mh_contrast2.gif";
base_image.onload = function(){
context2.drawImage(base_image, 0, 0, 400,300); /// scale up to fit?
// context = can2.getContext('2d');
var can3 = document.getElementById('buffercanvas');
var ctx3 = can3.getContext('2d');
ctx3.drawImage(can2, 0, 0);
ctx3.drawImage(can1, 0, 0);
saveFrameToServer();
/// saveImageToServer();
}
}
}
////////// SAVE FRAME TO SERVER ////////////////
function saveFrameToServer(){
// console.log("saving single frame to server");
var fn = frameIndex;
var canvas = document.getElementById("buffercanvas");
var dataURL = canvas.toDataURL();
$.ajax({
type: "POST",
url: "incl/functions.php",
data: {
functionType: "saveImage",
fileName : fn,
imgBase64: dataURL
},success: function (data) {
/// no callback functions since we need
/// to wait for all frames to be saved before
/// creating gif and posting to twitter
},
error: function (textStatus, errorThrown) {
console.log("error saving image");
}
});
}
function createGif(foldername, filename){
console.log("saving gif to server");
var foln = foldername; // folder all the frames are stored in
var filen = filename;
var filesArray = new Array();
for(var i = 0; i< frameIndex; i++){
filesArray.push("../uploads/" + i+ ".png");
}
console.log("files: " + filesArray.toString());
$.ajax({
type: "POST",
url: "incl/functions.php",
data: {
functionType: "createGif",
foldername : foln,
filename : filen,
srcnames : filesArray
},success: function (data) {
console.log("created gif");
/// now that gif is saved, post it with the twitter data
////console.log("POST GIF AND TWEET TO TWITTER: " + filen + " " + tweetCaption);
prepMemePost(filen);
},
error: function (textStatus, errorThrown) {
console.log("error saving image");
}
});
}
//////////// SAVE A FINAL STATIC MEME TO SERVER ////////////////////////
function saveImageToServer(){
// console.log("saving image to server");
var fn = randomString(10, "a");
var canvas = document.getElementById("buffercanvas");
var dataURL = canvas.toDataURL();
$.ajax({
type: "POST",
url: "incl/functions.php",
data: {
functionType: "saveImage",
fileName : fn,
imgBase64: dataURL
},success: function (data) {
prepMemePost(fn);
},
error: function (textStatus, errorThrown) {
console.log("error saving image");
}
});
}
/// little delay to make sure the gif has time to save
function prepMemePost(fn){
console.log("prep mempost for gif: " + fn);
setTimeout(function () {
postMeme(fn + ".gif");
}, 1000);
}
/// little delay to make sure the gif has time to upload before nuking all files
function prepFileDelete(fn){
setTimeout(function () {
deleteOldGif();
}, 5000);
}
//// POST FILENAME IMAGE TO TWITTER USING OATH /////////////
function postMeme(fn){
var filePath = fn;
console.log("sending uploaded image to twitter: " + fn);
console.log("posting tweet to twitter: " + tweetCaption);
///*
$.ajax({
type: "POST",
url: "incl/functions.php",
data: {
functionType: "imageToTwitter",
imageCaption :tweetCaption,
imagePath :filePath
},success: function (data) {
console.log("successful send: " + data);
prepFileDelete();
},
error: function (textStatus, errorThrown) {
console.log("error posting tweet");
}
//done after here
});
//*/
}
function deleteOldGif(){
console.log("deleting files from uploads");
$.ajax({
type: "POST",
url: "incl/functions.php",
data: {
functionType: "clearUploads"
/// fileName : theguid
},success: function (data) {
console.log("success empty uploads");
},
error: function (textStatus, errorThrown) {
console.log("error deleting uploads");
}
//done after here
});
}
</script>
</body>
</html>