-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
730 lines (675 loc) · 22.5 KB
/
db.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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
<?php
require_once('twitterphp.php');
class Tweet
{
//attributes of a tweet
public $key;
public $created_at;
public $id;
public $text;
public $source;
public $truncated;
public $in_reply_to_status_id;
public $in_reply_to_user_id;
public $in_reply_to_screen_name;
public $favorited;
public $isread;
public $userid;
public $username;
public $userscreen_name;
public $userprofile_image_url;
public $accountid;
private function __call($name, $arg){
return call_user_func_array(array($this, $name), $arg);
}
function __construct(){
$num = func_num_args();
$args = func_get_args();
switch($num){
case 0:
$this->__call('__construct0', $args);
break;
case 1:
$this->__call('__construct1', $args);
break;
case 2:
$this->__call('__construct2', $args);
break;
default:
throw new Exception();
}
}
//default empty
function __construct0(){
}
//from xml
function __construct1($statusxml){
$this->key = $statusxml->key;
$this->id = $statusxml->id;
$this->created_at = $statusxml->created_at;
$this->text = $statusxml->text;
$this->source = $statusxml->source;
$this->truncated = $statusxml->truncated;
$this->in_reply_to_status_id = $statusxml->in_reply_to_status_id;
$this->in_reply_to_user_id = $statusxml->in_reply_to_user_id;
$this->in_reply_to_screen_name = $statusxml->in_reply_to_screen_name;
$this->favorited = $statusxml->favorited;
$this->isread = 0;
$this->userid = $statusxml->user->id;
$this->username = $statusxml->user->name;
$this->userscreen_name = $statusxml->user->screen_name;
$this->userprofile_image_url = $statusxml->user->profile_image_url;
$this->accountid = $_SESSION['userLoggedInID'];
}
//from db row
function __construct2($row,$dummy){
$this->key = $ros[0];
$this->id = $row[1];
$this->created_at = $row[2];
$this->text = base64_decode($row[3]);
$this->source = $row[4];
$this->truncated = $row[5];
$this->in_reply_to_status_id = $row[6];
$this->in_reply_to_user_id = $row[7];
$this->in_reply_to_screen_name = $row[8];
$this->favorited = $row[9];
$this->isread = $row[10];
$this->userid = $row[11];
$this->username = $row[12];
$this->userscreen_name = $row[13];
$this->userprofile_image_url = $row[14];
$this->accountid = $_SESSION['userLoggedInID'];
}
function isEmpty(){
if (($this->id == "")||($this->text == ""))
{
return true;
}
return false;
}
function display(){
//$this->text = preg_replace('@(<a href="http://([\w-.]+)+(:\d+)?(/([\w/_.]*(\?\S+)?)?)?)@',
// '$1', $this->text);
//$this->text ='just saw @johndoe talking at #someforum about his product http://bit.ly/foo';
//$regex = '/http([s]?):\/\/([^\ \)$]*)/';
//$link_pattern = '<a href="http$1://$2" rel="nofollow" title="$2">http$1://$2</a>';
//$this->text = preg_replace($regex,$link_pattern,$this->text);
//$regex = '/@([a-zA-Z0-9_]*)/';
//$link_pattern = '<a href="http://twitter.com/$1" title="$1 profile on Twitter" rel="nofollow">@$1</a>';
//$this->text = preg_replace($regex,$link_pattern,$this->text);
//$regex = '/\#([a-zA-Z0-9_]*)/';
//$link_pattern = '<a href="http://search.twitter.com/search?q=%23$1" title="search for $1 on Twitter" rel="nofollow">\#$1</a>';
//$this->text = preg_replace($regex,$link_pattern,$this->text);
if ($this->isEmpty()) return false;
$this->text = htmlspecialchars($this->text);
print '<table><tr>';
print '<td width="50px"><div class="tweeticon"><img src="'. $this->userprofile_image_url . '" width="48px"></div></td><td>';
print '<table>';
print '<tr><td><b>'. $this->userscreen_name .':</b></td></tr>';
print '<tr><td>'. $this->text .'</td></tr>';
print '<tr><td><div class="tweetdate">'. date("F j, Y, g:i a",strtotime($this->created_at)) .'</div></td></tr>';
print '</table>';
print '<td></tr></table>';
}
}
class User
{
public $userid = 0;
public $username = '';
public $userscreen_name = '';
public $userpassword = '';
public $userdefaultzoom = '';
public $userlastlogon = '';
public $userlocation = '';
public $userdescription = '';
public $userprofile_image_url = '';
public $userurl = '';
public $userprotected = '';
public $useroauth_token = '';
public $useroauth_token_secret = '';
function display(){
print '<table><tr><td valign="top"><img src="'. $this->userprofile_image_url .'"></td>';
print '<td>ID: '. $this->userid;
print '<br>Name: '. $this->username;
print '<br>Screen Name: '. $this->userscreen_name;
print '<br>Password: '. $this->userpassword;
print '<br>Default Zoom: '. $this->userdefaultzoom;
print '<br>Last Logon: '. $this->userlastlogon;
print '<br>Location: '. $this->userlocation;
print '<br>Description: '. $this->userdescription;
print '<br><a href="'. $this->userurl .'">'. $this->userurl .'</a>';
print '<br>Token: '. $this->useroauth_token;
print '<br>Token Secret: '. $this->useroauth_token_secret;
print '<br>Protected: '. (bool)$this->userprotected . '</td></tr></table>';
}
private function __call($name, $arg){
return call_user_func_array(array($this, $name), $arg);
}
function __construct(){
$num = func_num_args();
$args = func_get_args();
switch($num){
case 0:
$this->__call('__construct0', null);
break;
case 3:
$this->__call('__construct3', $args);
break;
case 2:
$this->__call('__construct2', $args);
break;
default:
throw new Exception();
}
}
function __construct0(){
}
function __construct3($res,$oauth_token,$oauth_token_secret){
//print '|' . $res->id . '|<br>';
$this->userid = $res->id;
$this->username = $res->name;
$this->userscreen_name = $res->screen_name;
$this->userpassword = '';
$this->userdefaultzoom = 2;
$this->userlastlogon = date(DATE_RFC822);
$this->userlocation = $res->location;
$this->userdescription = $res->description;
$this->userprofile_image_url = $res->profile_image_url;
$this->userurl = $res->url;
$this->userprotected = $res->user_protected;
$this->useroauth_token = $oauth_token;
$this->useroauth_token_secret = $oauth_token_secret;
}
function __construct2($userscreen_name, $userpassword){
$t = new twitter();
$t->username='nmeierpolys';
$t->password='nathaniel1';
//$t->verifyCredentials();
//print_r($t->responseInfo);
$res = $t->showUser($userscreen_name);
if($res===false){
echo "ERROR logging in<hr/>";
echo "<pre>";
print_r($t->responseInfo);
echo "</pre>";
}else{
$this->userid = $res->id;
$this->username = $res->name;
$this->userscreen_name = $userscreen_name;
$this->userpassword = $userpassword;
$this->userdefaultzoom = 2;
$this->userlastlogon = date(DATE_RFC822);
$this->userlocation = $res->location;
$this->userdescription = $res->description;
$this->userprofile_image_url = $res->profile_image_url;
$this->userurl = $res->url;
$this->userprotected = $res->user_protected;
}
}
}
class DB
{
public $dbuser = 'twitteradmin2';
public $dbpass = 'Erroneous9';
public $dbdatabase = 'twitteradmin2';
public $usertable = 'userinfo';
public $tweettable = 'tweets';
public $dbhost = '72.167.233.88';
//GENERAL DB OPERATIONS
function open(){
//open db connection
mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
//select db
@mysql_select_db($this->dbdatabase) or die( "Unable to select database");
}
function close(){
//close db connection
mysql_close();
}
function query($querystr = ''){
//user query
if($querystr != '')
{
return mysql_query($querystr);
}else{
return "error: no query";
}
}
//USER OPERATIONS
function getAllUsers(){
$query = "SELECT * FROM ". $this->usertable . " WHERE 1";
$sqlresult = mysql_query($query);
//display results
$resultsize = mysql_num_rows($sqlresult);
$i=0;
while($i<$resultsize){
$userid = mysql_result($sqlresult,$i,"userid");
$username = mysql_result($sqlresult,$i,"userid");
$user = $this->getUserByID(intval($userid));
echo $i . ': <a href="./index.php?act=showlocaluser&id='. $userid .'">'.$username.'</a>';
$user->display();
echo '<hr>';
$i++;
}
}
function getUserLoggedIn($username,$password){
$query = "SELECT * FROM ". $this->usertable . " WHERE userscreen_name='". $username ."' AND userpassword='". $password ."'";
$sqlresult = mysql_query($query);
if(mysql_num_rows($sqlresult) != 0) // true if >0 results
{
return true;
}else{
return false;
}
}
function getUserByID($id){
$query = "SELECT * FROM ". $this->usertable . " WHERE userid='". $id ."'";
$sqlresult = mysql_query($query);
if(mysql_num_rows($sqlresult) == 0){
return new User();
}
$user = new User();
$user->userid = mysql_result($sqlresult,0,"userid");
$user->username = mysql_result($sqlresult,0,"username");
$user->userscreen_name = mysql_result($sqlresult,0,"userscreen_name");
$user->userpassword = mysql_result($sqlresult,0,"userpassword");
$user->userdefaultzoom = mysql_result($sqlresult,0,"userdefaultzoom");
$user->userlastlogon = mysql_result($sqlresult,0,"userlastlogon");
$user->userlocation = mysql_result($sqlresult,0,"userlocation");
$user->userdescription = mysql_result($sqlresult,0,"userdescription");
$user->userprofile_image_url = mysql_result($sqlresult,0,"userprofile_image_url");
$user->userurl = mysql_result($sqlresult,0,"userurl");
$user->userprotected = mysql_result($sqlresult,0,"userprotected");
$user->useroauth_token = mysql_result($sqlresult,0,"oauth_token");
$user->useroauth_token_secret = mysql_result($sqlresult,0,"oauth_token_secret");
return $user;
}
function getUserByScreenName($screen_name){
$query = "SELECT * FROM ". $this->usertable . " WHERE userscreen_name='". $screen_name ."'";
$sqlresult = mysql_query($query);
if(mysql_num_rows($sqlresult) == 0){
return new User();
}
$user = new User();
$user->userid = mysql_result($sqlresult,0,"userid");
$user->username = mysql_result($sqlresult,0,"username");
$user->userscreen_name = mysql_result($sqlresult,0,"userscreen_name");
$user->userpassword = mysql_result($sqlresult,0,"userpassword");
$user->userdefaultzoom = mysql_result($sqlresult,0,"userdefaultzoom");
$user->userlastlogon = mysql_result($sqlresult,0,"userlastlogon");
$user->userlocation = mysql_result($sqlresult,0,"userlocation");
$user->userdescription = mysql_result($sqlresult,0,"userdescription");
$user->userprofile_image_url = mysql_result($sqlresult,0,"userprofile_image_url");
$user->userurl = mysql_result($sqlresult,0,"userurl");
$user->userprotected = mysql_result($sqlresult,0,"userprotected");
$user->useroauth_token = mysql_result($sqlresult,0,"oauth_token");
$user->useroauth_token_secret = mysql_result($sqlresult,0,"oauth_token_secret");
return $user;
}
function insertUser($user){
$query = "INSERT INTO ". $this->usertable .
" VALUES ('".
$user->userid ."','".
$user->userscreen_name ."','".
$user->userpassword ."','".
$user->username ."','".
$user->userdefaultzoom ."','".
date( 'Y-m-d H:i:s', strtotime($user->userlastlogon)) ."','".
$user->userlocation ."','".
$user->userdescription ."','".
$user->userprofile_image_url ."','".
$user->userurl ."','".
$user->userprotected ."','".
$user->useroauth_token ."','".
$user->useroauth_token_secret ."')";
mysql_query($query);
}
function deleteAllUsers(){
$query = "DELETE FROM ". $this->usertable ." WHERE 1";
mysql_query($query);
}
function deleteUserByID($id){
$query = "DELETE FROM ". $this->usertable ." WHERE userid='". $id ."'";
mysql_query($query);
}
function deleteUserByScreenName($userscreen_name){
$query = "DELETE FROM ". $this->usertable ." WHERE userscreen_name='". $userscreen_name ."'";
mysql_query($query);
}
//TWEET OPERATIONS
function getTweetByID($id){
$query = "SELECT * FROM ". $this->tweettable . " WHERE id='". $id ."'";
$sqlresult = mysql_query($query);
if(mysql_num_rows($sqlresult) == 0){
return -1;
}
$tweet = new Tweet();
$tweet->id = mysql_result($sqlresult,0,"id");
$tweet->created_at = mysql_result($sqlresult,0,"created_at");
$tweet->text = base64_decode(mysql_result($sqlresult,0,"text"));
$tweet->source = mysql_result($sqlresult,0,"source");
$tweet->truncated = mysql_result($sqlresult,0,"truncated");
$tweet->in_reply_to_status_id = mysql_result($sqlresult,0,"in_reply_to_status_id");
$tweet->in_reply_to_user_id = mysql_result($sqlresult,0,"in_reply_to_user_id");
$tweet->in_reply_to_screen_name = mysql_result($sqlresult,0,"in_reply_to_screen_name");
$tweet->favorited = mysql_result($sqlresult,0,"favorited");
$tweet->isread = mysql_result($sqlresult,0,"isread");
$tweet->userid = mysql_result($sqlresult,0,"userid");
$tweet->username = mysql_result($sqlresult,0,"username");
$tweet->userscreen_name = mysql_result($sqlresult,0,"userscreen_name");
$tweet->userprofile_image_url = mysql_result($sqlresult,0,"userprofile_image_url");
return $tweet;
}
function getAllUnreadTweets(){
$sort = "DESC"; //switch DESC to ASC
$query = "SELECT * FROM ". $this->tweettable . " WHERE isread=0 AND accountid=" . $_SESSION['userLoggedInID'] . " ORDER BY created_at ". $sort;
$sqlresult = mysql_query($query);
//display results as Tweet objects
$resultsize = mysql_num_rows($sqlresult);
if($resultsize == 0){
print '<b> 0 Tweets Found <b><br>';
exit;
}
$arr = array();
//read results into array
for($i = 0;$i<$resultsize;$i++){
$row = mysql_fetch_array($sqlresult, MYSQL_NUM);
$arr[$i] = new Tweet($row,5);
}
$this->displayTweets($arr);
}
function getXUnreadTweets($count = 10,$start = 0){
$sort = "DESC"; //switch DESC to ASC
$query = "SELECT * FROM ". $this->tweettable . " WHERE isread=0 AND accountid=" . $_SESSION['userLoggedInID'] . " ORDER BY created_at ". $sort . " LIMIT " . $start . ", " . $count;
$sqlresult = mysql_query($query);
//display results as Tweet objects
$resultsize = mysql_num_rows($sqlresult);
if($resultsize == 0){
print '<b> 0 Tweets Found <b><br>';
exit;
}
$arr = array();
//read results into array
for($i = 0;$i<$resultsize;$i++){
$row = mysql_fetch_array($sqlresult, MYSQL_NUM);
$arr[$i] = new Tweet($row,5);
}
$this->displayTweets($arr);
}
function getAllReadTweets(){
$sort = "DESC"; //switch DESC to ASC
$query = "SELECT * FROM ". $this->tweettable . " WHERE isread=1 AND accountid=" . $_SESSION['userLoggedInID'] . " ORDER BY created_at ". $sort;
$sqlresult = mysql_query($query);
//display results as Tweet objects
$resultsize = mysql_num_rows($sqlresult);
if($resultsize == 0){
print '<b> 0 Tweets Found <b><br>';
exit;
}
$arr = array();
//read results into array
for($i = 0;$i<$resultsize;$i++){
$row = mysql_fetch_array($sqlresult, MYSQL_NUM);
$arr[$i] = new Tweet($row,5);
}
$this->displayTweets($arr);
}
function getAllTweets(){
if($_SESSION['userLoggedInID'] == "") {
print "Must be logged in to view tweets";
return -1;
}
$sort = "DESC"; //switch DESC to ASC
print 'For User: ' . $_SESSION['userLoggedInName'] . ' ';
$query = "SELECT * FROM ". $this->tweettable . " WHERE accountid='". $_SESSION['userLoggedInID'] . "' ORDER BY created_at ". $sort;
$sqlresult = mysql_query($query);
//display results as Tweet objects
$resultsize = mysql_num_rows($sqlresult);
if($resultsize == 0){
print '<b> 0 Tweets Found <b><br>';
return -1;
}
$arr = array();
//read results into array
for($i = 0;$i<$resultsize;$i++){
$row = mysql_fetch_array($sqlresult, MYSQL_NUM);
$arr[$i] = new Tweet($row,5);
}
$this->displayTweets($arr);
}
function getAllTweetsUserBlind(){
$sort = "DESC"; //switch DESC to ASC
print 'For User: ' . $_SESSION['userLoggedInID'];
$query = "SELECT * FROM ". $this->tweettable . " ORDER BY created_at ". $sort;
$sqlresult = mysql_query($query);
//display results as Tweet objects
$resultsize = mysql_num_rows($sqlresult);
if($resultsize == 0){
print '<b> 0 Tweets Found <b><br>';
return -1;
}
$arr = array();
//read results into array
for($i = 0;$i<$resultsize;$i++){
$row = mysql_fetch_array($sqlresult, MYSQL_NUM);
$arr[$i] = new Tweet($row,5);
}
$this->displayTweets($arr);
}
function displayTweets($tweetarray){
if($tweetarray == null){
print 'displayTweets error: no items in array';
break;
}
$count = count($tweetarray)-1;
print '<span id="tweettotalcount">'. $count .'</span> tweets:<br>';
print '<table>';
for($i = 0; $i <= $count;$i++){
if($tweetarray[$i] != null){
if(!$tweetarray[$i]->isEmpty())
{
print '<table><tr><tr onclick="highlight(this);"><td class="tweet" id="'. $tweetarray[$i]->id .'">';
$tweetarray[$i]->display();
print '</td></tr></table>';
}
}
}
print '</table>';
}
function getZoomedTweets($zoom = 0, $includeread = 0){
$sort = "DESC"; //switch DESC to ASC
if($_SESSION['userLoggedInID'] == NULL){
print 'Must be logged in to do that<br>';
return -1;
}
$query = "SELECT * FROM ". $this->tweettable . " WHERE isread=" . $includeread ." AND accountid=". $_SESSION['userLoggedInID'] ." ORDER BY created_at ". $sort;
$sqlresult = mysql_query($query);
//display results as Tweet objects
$resultsize = mysql_num_rows($sqlresult);
if($resultsize == 0){
print '<b> 0 Tweets Found <b><br>';
return -1;
}
//read results into array
for($i = 0;$i<=$resultsize;$i++){
$row = mysql_fetch_array($sqlresult, MYSQL_NUM);
$results[$i] = $row;
}
if($zoom == 0){
$zoom = 1;
}
//$numdesired = ($resultsize - ($resultsize % $zoom)) / $zoom;
$numdesired = round(($resultsize * $zoom) / 50);
$interval = $resultsize / $numdesired;
//print '<b> '. $numdesired .' Tweets Selected</b> ('. $resultsize .' total)<br>';
$arr = array();
//init all $arr[] slots to -1
for($i = 0; $i <= $numdesired; $i++){
$arr[$i] = null;
}
$selected = 0;
for($i = 0; $i <= $numdesired;$i++){
if($i == $numdesired){
//$selected = rand ( $numdesired * $zoom, $numdesired * $zoom + ($resultsize % $zoom) - 1);
$selected = rand ( ($i-1) * $interval, $i * $interval);
} else {
//$selected = rand ( $i * $zoom, $i * $zoom + ($zoom - 1)); //get range of width $zoom, starting at $zoom*$i
$selected = rand ( ($i-1) * $interval, $i * $interval);
}
$tweet = new Tweet($results[$selected],5);
//$arr[$i] = $tweet;
if (!$tweet->isEmpty()) $arr[++$arrIndex] = $tweet;
}
$this->displayTweets($arr);
}
function insertUpdateTweet($tweet){
$querydelete = "DELETE FROM ". $this->tweettable .
" WHERE id='". $tweet->id ."' AND accountid='". $_SESSION['userLoggedInID'] ."'";
$queryinsert = "INSERT INTO ". $this->tweettable .
"(id,created_at,
text,
source,
truncated,
in_reply_to_status_id,
in_reply_to_user_id,
in_reply_to_screen_name,
favorited,
isread,
userid,
username,
userscreen_name,
userprofile_image_url,
accountid
) VALUES ('".
$tweet->id ."','".
date( 'Y-m-d H:i:s', strtotime($tweet->created_at)) ."','".
base64_encode($tweet->text) ."','".
$tweet->source ."','".
$tweet->truncated ."','".
$tweet->in_reply_to_status_id ."','".
$tweet->in_reply_to_user_id ."','".
$tweet->in_reply_to_screen_name ."','".
$tweet->favorited ."','".
$tweet->isread ."','".
$tweet->userid ."','".
$tweet->username ."','".
$tweet->userscreen_name ."','".
$tweet->userprofile_image_url ."','".
$tweet->accountid ."')";
mysql_query($querydelete);
mysql_query($queryinsert);
}
function insertTweet($tweet){
$query = "INSERT INTO ". $this->tweettable .
"(id,created_at,
text,
source,
truncated,
in_reply_to_status_id,
in_reply_to_user_id,
in_reply_to_screen_name,
favorited,
isread,
userid,
username,
userscreen_name,
userprofile_image_url,
accountid
) VALUES ('".
$tweet->id ."','".
date( 'Y-m-d H:i:s', strtotime($tweet->created_at)) ."','".
base64_encode($tweet->text) ."','".
$tweet->source ."','".
$tweet->truncated ."','".
$tweet->in_reply_to_status_id ."','".
$tweet->in_reply_to_user_id ."','".
$tweet->in_reply_to_screen_name ."','".
$tweet->favorited ."','".
$tweet->isread ."','".
$tweet->userid ."','".
$tweet->username ."','".
$tweet->userscreen_name ."','".
$tweet->userprofile_image_url ."','".
$tweet->accountid ."')";
//print '<br>'.$query.'<br>';
mysql_query($query);
}
function deleteUserTweets(){
if($_SESSION['userLoggedInID'] == NULL){
print 'Must be logged in to do that<br>';
return -1;
} else {
$query = "DELETE FROM ". $this->tweettable ." WHERE accountid=". $_SESSION['userLoggedInID'];
mysql_query($query);
}
print $query;
}
function deleteTweetByID($id){
$query = "DELETE FROM ". $this->tweettable ." WHERE id='". $id ."'";
mysql_query($query);
}
function readTweetByID($id,$userid = NULL){
if($userid == NULL){
$query = "UPDATE ". $this->tweettable ." SET isread=1 WHERE id='". $id ."'";
} else {
$query = "UPDATE ". $this->tweettable ." SET isread=1 WHERE id='". $id ."' AND userid='". $userid ."'";
}
mysql_query($query);
}
function deleteAllTweets(){
$query = "DELETE FROM ". $this->tweettable ."WHERE 1";
print $query;
mysql_query($query);
}
function deleteTweetsByUserScreenName($userscreen_name){
$query = "DELETE FROM ". $this->tweettable ." WHERE userscreen_name='". $userscreen_name ."'";
mysql_query($query);
}
}
/* OLD Testing
$t= new twitter();
$t->username='nmeierpolys';
$t->password='nathaniel1';
//1
$status = $t->showSingleUpdate('1472669360');
$tweet1 = new Tweet($status);
$tweet1->display();
//2
$status = $t->showSingleUpdate('2241944628');
$tweet2 = new Tweet($status);
$tweet2->display();
//$t->showZoomedTweets($skipevery,200);
//$t->showZoomedTweets(2,100);
$user = new User('nmeierpolys','nathaniel1');
//var_dump($tweet);
//$user->show();
$user2 = new User('sirpython','sirpythonpass');
//$user2->show();
//Show rate limits
$t1= new twitter();
$res = $t1->rateLimit();
print '<b>IP limit: ';
var_dump($res);
print '</b><br>';
$t1= new twitter();
$t1->username='nmeierpolys';
$t1->password='nathaniel1';
$res = $t1->rateLimit();
print '<b>User limit: ';
var_dump($res);
print '</b><br>';
$db = new DB();
$db->open();
//$db->getAllUsers();
$db->deleteAllTweets();
$db->insertTweet($tweet1);
$db->insertTweet($tweet2);
$db->getAllTweets();
$db->deleteAllUsers();
$db->insertUser($user);
$db->insertUser($user2);
$db->getAllUsers();
//print $db->getLoggedIn('nmeierpolysnmeierpolys','nathaniel1');
$db->close();
*/
?>