-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmotor.php
949 lines (768 loc) · 26.4 KB
/
motor.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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
<?php
include('Settings.php');
function connect()
{
global $localhost, $dbuser, $dbpass, $dbname;
// ################################################
// ######### connect + select database ###########
// ################################################
$conn = mysqli_connect($localhost, $dbuser, $dbpass) or die('Could not connect: ' . mysqli_error($conn));
mysqli_select_db($conn, $dbname) or die ("Can't use database $dbname! : " . mysqli_error($conn));
//mysqli_set_charset('utf8',$conn);
return $conn;
}
$db = connect();
function addinfo()
{
global $dbtableinfo, $db;
// #################################################################
// ######### add IP and user-agent and time or update it ###########
// #################################################################
// gather user data
$ip = $_SERVER["REMOTE_ADDR"];
$id = getmyreferid();
$agent = $_SERVER["HTTP_USER_AGENT"];
$datetime = time();
(int)$refer = mysqli_real_escape_string($db, @$_GET['ref']);
if (empty($refer)) {
$refer = -1;
}
if (!mysqli_num_rows(mysqli_query($db, "SELECT ip_address FROM $dbtableinfo WHERE ip_address = '$ip'"))) // check if the IP is in database
{
//If not , add it.
mysqli_query($db, "INSERT INTO $dbtableinfo (ip_address, user_agent, datetime, refer_id, lastconn) VALUES('$ip', '$agent', '$datetime', '$refer', '$datetime')") or die('Could not add IP: ' . mysqli_error($db));
} else {
//Else, update some rows
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM $dbtableinfo WHERE id='$id'"));
$exp = $row['exp'];
$lvl = $row['lvl'];
$lastconn = $row['lastconn'];
$multiplier = $row['multiplier'];
//Edit the lastconn entry...
$remainingvisits = 3 * $multiplier;
//if(time() - (int)$lastconn > 600) { //If last connection is greater than ten mintutes update it.
mysqli_query($db, "UPDATE $dbtableinfo SET lastconn='$datetime' WHERE ip_address='$ip'") or die('Could not update user info: ' . mysqli_error($db));
//}
//Restore everything if today is a new day.
if (!stilltoday($lastconn)) {
//Dialy bonus
mysqli_query($db, "UPDATE $dbtableinfo SET remainingvisits='$remainingvisits' WHERE ip_address='$ip'") or die('Could not update user info: ' . mysqli_error($db));
}
$proceed = false;
if ($refer != null) //There is a referer, and a refered user
{
//Refer data
$row2 = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM $dbtableinfo WHERE id='$refer'"));
$rexp = @$row2['exp'];
$rlvl = @$row2['lvl'];
$rmultiplier = @$row2['multiplier'];
//There is the part that checks the cheats...
if ($refer != getmyreferid()) //The simplest thing is check that the current user is the same in the variable index.php?ref=id
{
if (!checkisbanned($ip) && maxviewsperday() && userexists($refer)) //Check if the current visitor's ip is banned and the maxviewsperday is actually available.
{
//For Debugging...
/*setpoints($refer, 1);
newvisited($refer, time());*/
if ($row['visitarray'] == null) //If the visit array is empty that means that the user didn't visited anything yet.
{
$proceed = true;
} else //The user has visited something.
{
$visitarray = (array)unserialize($row['visitarray']); //Unserialize the data and convert into a Array
if (time() - $visitarray[$refer] > 86400) //Check if the refer has been visited before and compare with the actual time with the last visit, if the last visit is greater than 1 day add the points.
{
$proceed = true;
}
}
}
} //Else for pusishment, maybe? haha :3
//Other checks (Functions: bannedip() (for proxies and bad boys), (Hecho)
//Checklastconn() (Checks the last connection to some user, and if it's greater than X seconds add points, if not wait) (Hecho)
//MaxViewsperDay() (If that function return false, no points will be added) (Hecho))
}
if ($proceed) {
setpoints($refer, 1 * $rmultiplier);
setexperience($refer, 1 * $rmultiplier);
setexperience($id, 1 * $multiplier / $rmultiplier);
newvisited($refer, time());
removeremvisit();
recalculatelvl($refer, $rlvl, $rexp);
recalculatelvl($id, $lvl, $exp);
sumvisit($refer);
}
}
}
function sumvisit($id)
{
global $dbtableinfo, $db;
mysqli_query($db, "UPDATE $dbtableinfo SET numvsts = numvsts + 1 WHERE id='$id'");
}
function getdailybonus()
{
global $dbtableinfo, $db;
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT remainingvisits as remvsts, lvl as lvl, multiplier as mult FROM $dbtableinfo WHERE id='$id'"));
if (!$row['remvsts']) {
$lvl = $row['lvl'];
$mult = $row['mult'];
$morepoints = round(pow(120 * $mult, 1 + $lvl / 100));
setpoints($id, $morepoints);
}
}
function newvisited($user, $date)
{
global $dbtableinfo, $db;
$id = getmyreferid();
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT visitarray FROM $dbtableinfo WHERE id='$id'"));
if ($row['visitarray'] != null) {
$visitarray = (array)unserialize($row['visitarray']);
$visitarray[$user] = $date;
$svisit = serialize($visitarray);
} else {
$visitarray = array($user => $date);
$svisit = serialize($visitarray);
}
mysqli_query($db, "UPDATE $dbtableinfo SET visitarray='$svisit' WHERE id='$id'");
}
function removeremvisit()
{
global $dbtableinfo, $db;
$id = getmyreferid();
mysqli_query($db, "UPDATE $dbtableinfo SET remainingvisits = remainingvisits - 1 WHERE id='$id'");
}
function maxviewsperday()
{
global $dbtableinfo, $db;
$id = getmyreferid();
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT remainingvisits FROM $dbtableinfo WHERE id='$id'"));
if ($row['remainingvisits']) //The actual visits is true because it's greater than 1
{
return true;
} else {
return false;
}
}
function uptlastclaim()
{
global $dbtableinfo, $db;
$id = getmyreferid();
$now = time();
mysqli_query($db, "UPDATE $dbtableinfo SET lastclaim = '$now' WHERE id='$id'");
}
function checkisbanned($ip)
{
global $db;
if (mysqli_num_rows(mysqli_query($db, "SELECT id FROM bannedips WHERE ip='$ip'"))) {
return true;
} else {
return false;
}
}
function stilltoday($date) //Comprueba si la fecha está todavía dentro de este rango horario. (00:00:00 - 23:59:59)
{
$dateFrom = date("Y-m-d", $date);
$dateTo = date("Y-m-d", time());
if ($dateTo == $dateFrom) {
return true;
} else {
return false;
}
}
function thisexists() //Check if there is any account with the current visitor's IP
{
global $dbtableinfo, $db;
$id = getmyreferid();
if (mysqli_num_rows(mysqli_query($db, "SELECT id FROM $dbtableinfo WHERE id='$id'"))) {
return true;
} else {
return false;
}
}
function userexists($id) //Check if there is any account with the current visitor's IP
{
global $dbtableinfo, $db;
if (mysqli_num_rows(mysqli_query($db, "SELECT id FROM $dbtableinfo WHERE id='$id'"))) {
return true;
} else {
return false;
}
}
function getmyreferid()
{
global $dbtableinfo, $db;
$ip = $_SERVER["REMOTE_ADDR"];
$query = mysqli_query($db, "SELECT id FROM $dbtableinfo WHERE ip_address='$ip' AND acc_prior > -3 LIMIT 0,1");
if (mysqli_num_rows($query)) {
$row = mysqli_fetch_assoc($query);
return $row['id'];
} /*else {
die('Hubo un error al procesar la información. #0001');
}*/
return 0;
}
function formatnumber($number, $dots = true)
{
if ($dots) //Commas to dots
{
$str = str_replace(',', '.', $number);
return $str;
} else //Dots to commas
{
$str = str_replace('.', ',', $number);
return $str;
}
}
function getpointsbyid($id)
{
global $dbtableinfo, $db;
$query = mysqli_query($db, "SELECT points FROM $dbtableinfo WHERE id='$id'");
$row = mysqli_fetch_assoc($query);
$rowd = $row['points'];
return (int)$rowd;
}
function getexpbyid($id)
{
global $dbtableinfo, $db;
$query = mysqli_query($db, "SELECT exp FROM $dbtableinfo WHERE id='$id'");
$row = mysqli_fetch_assoc($query);
$rowd = $row['exp'];
return (int)$rowd;
}
function getlvlbyid($id)
{
global $dbtableinfo, $db;
$query = mysqli_query($db, "SELECT lvl FROM $dbtableinfo WHERE id='$id'");
$row = mysqli_fetch_assoc($query);
$rowd = $row['lvl'];
return (int)$rowd;
}
function getmultbyid($id)
{
global $dbtableinfo, $db;
$query = mysqli_query($db, "SELECT multiplier FROM $dbtableinfo WHERE id='$id'");
$row = mysqli_fetch_assoc($query);
$rowd = $row['multiplier'];
return (int)$rowd;
}
function givepointsinactivation($quantity)
{
$id = getmyreferid();
setpoints($id, $quantity);
}
function recurseTree($var)
{
$out = '<li>';
foreach ($var as $v) {
if (is_array($v)) {
$out .= '<ul>' . recurseTree($v) . '</ul>';
} else {
$out .= $v;
}
}
return $out . '</li>';
}
function getmypoints($round = false, $texted = true, $commas = true, $dots = true)
{
global $dbtableinfo, $db;
$ip = $_SERVER["REMOTE_ADDR"];
$query = mysqli_query($db, "SELECT points FROM $dbtableinfo WHERE ip_address='$ip'");
$string = "";
if (thisexists()) {
$row = mysqli_fetch_assoc($query);
$rowd = $row['points'];
if ($texted) {
if ($round) {
if ((int)$rowd == 1) {
$string = $rowd . " point";
} else if ((int)$rowd >= 1000000000000000000000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000000000000000000000, 1), $dots) . "D points";
} else if ((int)$rowd >= 1000000000000000000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000000000000000000, 1), $dots) . "N points";
} else if ((int)$rowd >= 1000000000000000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000000000000000, 1), $dots) . "O points";
} else if ((int)$rowd >= 1000000000000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000000000000, 1), $dots) . "Spt points";
} else if ((int)$rowd >= 1000000000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000000000, 1), $dots) . "Sx points";
} else if ((int)$rowd >= 1000000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000000, 1), $dots) . "Q points";
} else if ((int)$rowd >= 1000000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000000, 1), $dots) . "Ct points";
} else if ((int)$rowd >= 1000000000000) {
$string = formatnumber(round((int)$rowd / 1000000000000, 1), $dots) . "T points";
} else if ((int)$rowd >= 1000000000) {
$string = formatnumber(round((int)$rowd / 1000000000, 1), $dots) . "B points";
} else if ((int)$rowd >= 1000000) {
$string = formatnumber(round((int)$rowd / 1000000, 1), $dots) . "M points";
} else if ((int)$rowd >= 1000) {
$string = formatnumber(round((int)$rowd / 1000, 1), $dots) . "k points";
} else {
$string = $rowd . " points";
}
return $string;
} else {
if ($commas || $dots) {
if ($commas) {
if ($rowd == 1) {
$string = number_format($rowd, 0, ',', '.') . " point";
} else {
$string = number_format($rowd, 0, ',', '.') . " points";
}
} else if ($dots) {
if ($rowd == 1) {
$string = number_format($rowd, 0, '.', ',') . " point";
} else {
$string = number_format($rowd, 0, '.', ',') . " points";
}
}
return $string;
} else {
if ((int)$rowd == 1) {
$string = $rowd . " point";
} else {
$string = $rowd . " points";
}
return $string;
}
}
} else {
return (int)$rowd;
}
} else {
die('Hubo un error al procesar la información. #0002');
}
}
function specialnumformat($num, $dots = false)
{
$string = "";
if ($num >= 1000000000000000000000000000000000) {
$string = formatnumber(round($num / 1000000000000000000000000000000000, 1), $dots) . "D";
} else if ($num >= 1000000000000000000000000000000) {
$string = formatnumber(round($num / 1000000000000000000000000000000, 1), $dots) . "N";
} else if ($num >= 1000000000000000000000000000) {
$string = formatnumber(round($num / 1000000000000000000000000000, 1), $dots) . "O";
} else if ($num >= 1000000000000000000000000) {
$string = formatnumber(round($num / 1000000000000000000000000, 1), $dots) . "Spt";
} else if ($num >= 1000000000000000000000) {
$string = formatnumber(round($num / 1000000000000000000000, 1), $dots) . "Sx";
} else if ($num >= 1000000000000000000) {
$string = formatnumber(round($num / 1000000000000000000, 1), $dots) . "Q";
} else if ($num >= 1000000000000000) {
$string = formatnumber(round($num / 1000000000000000, 1), $dots) . "Ct";
} else if ($num >= 1000000000000) {
$string = formatnumber(round($num / 1000000000000, 1), $dots) . "T";
} else if ($num >= 1000000000) {
$string = formatnumber(round($num / 1000000000, 1), $dots) . "B";
} else if ($num >= 1000000) {
$string = formatnumber(round($num / 1000000, 1), $dots) . "M";
} else if ($num >= 1000) {
$string = formatnumber(round($num / 1000, 1), $dots) . "k";
} else {
$string = $num;
}
return $string;
}
function setpoints($id, $pointsquantity, $type = 0)
{
global $dbtableinfo;
$allpoints = getpointsbyid($id);
if ($type == 0) //Add
{
$allpoints += $pointsquantity;
} else if ($type == 1) //Substract
{
$allpoints -= $pointsquantity;
} else if ($type == 2) //Multiply
{
$allpoints *= $pointsquantity;
} else if ($type == 3) //Divide
{
$allpoints /= $pointsquantity;
}
if (thisexists()) {
mysqli_query($db, "UPDATE $dbtableinfo SET points = $allpoints WHERE id='$id'");
} else {
die('Hubo un error al procesar la información. #0003');
}
}
function setexperience($id, $expquantity, $type = 0)
{
global $dbtableinfo;
$allexp = getexpbyid($id);
$cexpq = ceil($expquantity);
if ($type == 0) //Add
{
$allexp += $cexpq;
} else if ($type == 1) //Substract
{
$allexp -= $cexpq;
} else if ($type == 2) //Multiply
{
$allexp *= $cexpq;
} else if ($type == 3) //Divide
{
$allexp /= $cexpq;
}
if (thisexists()) {
mysqli_query($db, "UPDATE $dbtableinfo SET exp = $allexp WHERE id='$id'");
} else {
die('Hubo un error al procesar la información. #0003');
}
}
function recalculatelvl($id, $actualvl, $exp)
{
global $dbtableinfo, $db;
$newlvl = $actualvl;
$reachednewlvl = false;
if (calculateexpfromlvl($actualvl, true) < $exp) {
for ($i = $actualvl; $i < 1000; $i++) //Check with the next 1000 lvls
{
if (calculateexpfromlvl($i, true) > $exp) {
$newlvl = $i;
$reachednewlvl = true;
break;
}
}
}
mysqli_query($db, "UPDATE $dbtableinfo SET lvl = '$newlvl' WHERE id='$id'");
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT multiplier FROM $dbtableinfo WHERE id='$id'"));;
$actualmulty = $row['multiplier'];
$newmulti = calculatemultfromlvl($newlvl);
if ($newmulti > $actualmulty) {
mysqli_query($db, "UPDATE $dbtableinfo SET multiplier = '$newmulti' WHERE id='$id'");
}
/*if(strlen($newlvl) > 1) {
$roundedlvl = (int)substr($newlvl, -1);
} else {
$roundedlvl = (int)$newlvl;
}
$templvl = (int)$newlvl;
$tempmulty = 1;
if($roundedlvl < 5)
{
$templvl = $newlvl - $roundedlvl;
} else if($roundedlvl > 5)
{
$templvl = $newlvl - $roundedlvl + 5;
}
if($templvl % 5 === 0)
{
if($templvl/5+1 >= $multiplier)
{
$newmult = $templvl/5+1;
mysqli_query($db, "UPDATE $dbtableinfo SET multiplier = '$newmult' WHERE id='$id'");
}
} else
{
die('Hubo un error matemático. #0001');
}*/
if ($reachednewlvl) {
$points = getpointsbyid($id);
$points = calculatebonusptsfromlvl($newlvl, true);
setpoints($id, $points);
}
//We have to set the multiplier (1 more) each five levels
}
function calculateexpfromlvl($lvl, $accumulative = false)
{
//3 is the exp of the lvl 0
(int)$number = 0;
if ($accumulative) {
for ($i = 0; $i <= $lvl; ++$i) {
if ($i < 130) {
$number += round(3 + $i * pow(($i + 1), (1 + $i / 100)), 0);
} else {
$number += 9630913;
}
}
} else {
if ($lvl < 130) {
$number = round(3 + $lvl * pow(($lvl + 1), (1 + $lvl / 100)), 0);
} else {
$number = 9630913;
}
}
return $number;
}
function calculatebonusptsfromlvl($lvl, $accumulative = false)
{
//5 is the points gave in the lvl 0
(int)$number = 0;
if ($accumulative) {
for ($i = 0; $i <= $lvl; $i++) {
if ($i < 100) {
$number += round(5 + pow($i, 2 + $i / 100)); //Nan when $i = -1
} else {
$number += 1000000;
}
}
} else {
if ($lvl < 100) {
$number = round(5 + pow($lvl, 2 + $lvl / 100));
} else {
$number = 1000000;
}
}
return $number;
}
function calculatemultfromlvl($lvl)
{
$number = floor($lvl / 5);
if ($number == 0) {
$number = 1;
}
return $number;
}
function calculatevisitstoreachlvl($lvl, $accumulative = false)
{
(int)$number = 0;
if ($accumulative) {
for ($i = 0; $i <= $lvl; $i++) {
if ($i < 130) {
$number += calculateexpfromlvl($i) / calculatemultfromlvl($i);
} else {
$number += 9630913 / calculatemultfromlvl($i);
}
}
} else {
if ($lvl < 130) {
$number = calculateexpfromlvl($lvl) / calculatemultfromlvl($lvl);
} else {
$number = 9630913 / calculatemultfromlvl($lvl);
}
}
return $number;
}
function strdate($date)
{
$str_time = "";
if ($date == null) {
$date = time();
}
$diff = time() - $date;
if ($diff < 3) {
$str_time = 'unos instantes.';
} else if ($diff < 10) {
$str_time = 'unos segundos.';
} else if ($diff < 60) {
$str_time = $diff . ' segundos.';
} else if ($diff >= 60 && $diff < 120) {
$str_time = floor($diff / 60) . ' minuto';
} else if ($diff < 3600) {
$str_time = floor($diff / 60) . ' minutos';
} else if ($diff >= 3600 && $diff < 7200) {
$str_time = floor($diff / 3600) . ' hora';
} else if ($diff < 86400) {
$str_time = floor($diff / 3600) . ' horas';
} else if ($diff >= 86400 && $diff < 86400 * 2) {
$str_time = floor($diff / 86400) . ' día';
} else if ($diff < 604800) {
$str_time = floor($diff / 86400) . ' días';
} else if ($diff >= 604800 && $diff < 604800 * 2) {
$str_time = floor($diff / 604800) . ' semana';
} else if ($diff < 2592000) {
$str_time = floor($diff / 604800) . ' semanas';
} else if ($diff >= 2592000 && $diff < 2592000 * 2) {
$str_time = floor($diff / 2592000) . ' mes';
} else if ($diff < 31536000) {
$str_time = floor($diff / 2592000) . ' meses';
} else if ($diff >= 31536000 && $diff < 31536000 * 2) {
$str_time = floor($diff / 31536000) . ' año';
} else {
$str_time = floor($diff / 31536000) . ' años';
}
return $str_time;
}
function getcssclassbyreporttype($type_report)
{
return 0;
}
function getLocationInfoByIp($ip)
{
if ($ip == null) {
$ip = $_SERVER["REMOTE_ADDR"];
}
$ip_data = @json_decode
(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
if ($ip_data && $ip_data->geoplugin_countryName != null) {
$result['city'] = $ip_data->geoplugin_city;
$result['region'] = $ip_data->geoplugin_region;
$result['areaCode'] = $ip_data->geoplugin_areaCode;
$result['dmaCode'] = $ip_data->geoplugin_dmaCode;
$result['countryCode'] = $ip_data->geoplugin_countryCode;
$result['country'] = $ip_data->geoplugin_countryName;
$result['continentCode'] = $ip_data->geoplugin_continentCode;
$result['latitude'] = $ip_data->geoplugin_latitude;
$result['longitude'] = $ip_data->geoplugin_longitude;
$result['regionCode'] = $ip_data->geoplugin_regionCode;
$result['region'] = $ip_data->geoplugin_regionName;
$result['currencyCode'] = $ip_data->geoplugin_currencyCode;
$result['currencySymbol'] = $ip_data->geoplugin_currencySymbol;
$result['currencySymbol_UTF8'] = $ip_data->geoplugin_currencySymbol_UTF8;
$result['currencyConverter'] = $ip_data->geoplugin_currencyConverter;
}
return $result;
}
function getprior($rango)
{
switch ($rango) {
case 'deleted':
return -3;
break;
case 'banned':
return -2;
break;
case 'troll':
return -1;
break;
case 'user':
case 'free':
return 0;
break;
case 'ureg':
case 'registered':
case 'actived':
case 'richman':
case 'rich':
case 'celebrity':
case 'noted-user':
return 1;
break;
case 'colaborator':
case 'tvip':
case 'helper':
case 'wiki':
case 'recruiter':
case 'youtuber':
case 'super-user':
case 'superu':
case 'superuser':
case 'abon':
return 2;
break;
case 'vip':
case 'premium':
case 'temp-mod':
return 3;
break;
case 'moderator':
case 'mod':
case 'temp-admin':
case 'scripter':
case 'programmer':
case 'bug-reporter':
case 'bug-fixer':
case 'webopt':
return 4;
break;
case 'supermod':
case 'admin':
case 'administrator':
case 'temp-boss':
case 'admi':
return 5;
break;
case 'superadmin':
case 'boss':
case 'adm-jefe':
case 'co-owner':
return 6;
break;
case 'owner':
case 'temp-hacker':
return 7;
break;
case 'hacker':
return 8;
break;
default:
return 0;
break;
}
}
function isnew($post_type)
{
global $dbtableinfo;
$id = getmyreferid();
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT notifications FROM $dbtableinfo WHERE id='$id'"));
$notarray = (array)unserialize($row['notifications']);
if ($notarray[$post_type]) {
return false;
} else {
return true;
}
}
function setreaded($post_type)
{
global $dbtableinfo, $db;
$id = getmyreferid();
$row = mysqli_fetch_assoc(mysqli_query($db, "SELECT notifications FROM $dbtableinfo WHERE id='$id'"));
$notarray = (array)unserialize($row['notifications']);
$notarray[$post_type] = true;
$snot = serialize($notarray);
mysqli_query($db, "UPDATE $dbtableinfo SET notifications='$snot' WHERE id='$id'");
}
function timequery()
{
static $querytime_begin;
list($usec, $sec) = explode(' ', microtime());
if (!isset($querytime_begin)) {
$querytime_begin = ((float)$usec + (float)$sec);
} else {
$querytime = (((float)$usec + (float)$sec)) - $querytime_begin;
echo sprintf('<center style="position:relative;top:-15px;">La consulta tardó %01.5f segundos</center>', $querytime);
}
}
function getrand($array, $cur, $max)
{
$num = rand(1, $max);
while (true) {
if (!in_array($num, $array, true)) {
if ($cur > $max) {
die('El valor máximo es menor que el valor actual.');
}
break;
} else {
$num = rand(1, $max);
}
}
$array[$cur] = $num;
return $array;
}
function perenc($str)
{
$newstr = "";
for ($i = 0; $i < strlen($str); $i++) {
$newstr .= "%" . dechex(ord(substr($str, $i, 1)));
}
return $newstr;
}
function perdec($dec)
{
if(!isset($dec)) return null;
$newstr = "";
$decarray = explode("%", $dec);
for ($i = 0; $i < count($decarray); $i++) {
$newstr .= chr(hexdec($decarray[$i]));
}
return $newstr;
}
function mb_unserialize($string)
{
$string = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $string);
return unserialize($string);
}
function setarraytocookie($str_index, $content)
{
$carray = unserialize($_COOKIE['TMDCookie']);
$carray[$str_index] = $content;
$carray = serialize($carray);
setcookie("TMDCookie", "", time() - 3600);
setcookie("TMDCookie", $carray, time() + 365 * 86400);
}
function getvaluefromcookie($index_to_search)
{
$carray = unserialize($_COOKIE['TMDCookie']);
return $carray[$index_to_search];
}
?>