PageRenderTime 55ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/TBDev/installer_v4_1/include/function_happyhour.php

https://github.com/cybernet/CyBerFuN-CoDeX
PHP | 101 lines | 90 code | 1 blank | 10 comment | 29 complexity | c9a28a4b90cf7fbe1e955ef04bd900a7 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. if(!defined('PUBLIC_ACCESS')) die('Fuck off - You cant access scripts directly fool !');
  3. //made by putyn @tbdev 06.11.2008
  4. function happyHour($action) {
  5. global $CACHE ;
  6. //generate happy hour
  7. if ($action == "generate")
  8. {
  9. $nextDay = date("Y-m-d" , time()+86400 );
  10. $nextHoura = mt_rand(0,2);
  11. if ($nextHoura == 2)
  12. $nextHourb = mt_rand(0,3);
  13. else
  14. $nextHourb = mt_rand(0,9);
  15. $nextHour = $nextHoura.$nextHourb;
  16. $nextMina = mt_rand(0,5);
  17. $nextMinb = mt_rand(0,9);
  18. $nextMin = $nextMina.$nextMinb;
  19. $happyHour = $nextDay." ".$nextHour.":".$nextMin."";
  20. return $happyHour;
  21. }
  22. $file = "$CACHE/happyhour.txt"; //==linux
  23. //$file = "C://AppServ/www/cache/happyhour.txt"; //==windows *change* appserv if you use xammp
  24. $happy = unserialize(file_get_contents($file));
  25. $happyHour = strtotime($happy["time"]);
  26. $happyDate = $happyHour;
  27. $curDate = time();
  28. $nextDate= $happyHour + 3600;
  29. //action check
  30. if ($action == "check"){
  31. if ($happyDate < $curDate && $nextDate >= $curDate )
  32. return true;
  33. }
  34. //action time left
  35. if ($action == "time"){
  36. $timeLeft = mkprettytime(($happyHour + 3600)-time());
  37. $timeLeft = explode(":",$timeLeft);
  38. $time = ($timeLeft[0]." min : ".$timeLeft[1]." sec");
  39. return $time;
  40. }
  41. //this will set all torrent free or just one category
  42. if ($action == "todo")
  43. {
  44. $act = rand(1,2);
  45. if ($act == 1)
  46. $todo = 255; // this will mean that all the torrent are free
  47. elseif ($act == 2)
  48. $todo = rand(1,16); // only one cat will be free || remember to change the number of categories i have 16 but you may have more
  49. return $todo ;
  50. }
  51. //this will generate the multiplier so every torrent downloaded in the happy hour will have upload multiplied but this
  52. if ($action == "multiplier")
  53. {
  54. $multiplier = rand(11,55)/ 10; //max value of the multiplier will be 5,5 || you could change it to a higher or a lower value
  55. return $multiplier;
  56. }
  57. }
  58. function happyCheck($action, $id=NUll){
  59. global $CACHE;
  60. $file = "$CACHE/happyhour.txt"; //==linux
  61. //$file = "C://AppServ/www/cache/happyhour.txt"; //==windows *change* appserv if you use xammp
  62. $happy = unserialize(file_get_contents($file));
  63. $happycheck = $happy["catid"];
  64. if ($action == "check")
  65. return $happycheck;
  66. if ( $action == "checkid" && (($happycheck == "255") || $happycheck == $id ))
  67. return true;
  68. }
  69. function happyFile($act){
  70. global $CACHE;
  71. $f = "$CACHE/happyhour.txt"; //==linux
  72. //$f = "C://AppServ/www/cache/happyhour.txt"; //==windows *change* appserv if you use xammp
  73. $happy = unserialize(file_get_contents($f));
  74. if ($act == "set"){
  75. $array_happy = array (
  76. 'time' => happyHour("generate"),
  77. 'status' => '1',
  78. 'catid' => happyHour("todo")
  79. );
  80. } elseif ($act == "reset") {
  81. $array_happy = array (
  82. 'time' => $happy["time"],
  83. 'status' => '0',
  84. 'catid' => $happy["catid"]
  85. );
  86. }
  87. $array_happy = serialize($array_happy);
  88. $f = "$CACHE/happyhour.txt"; //==linux
  89. //$f = "C://AppServ/www/cache/happyhour.txt"; //==windows *change* appserv if you use xammp
  90. $file = fopen($f, 'w');
  91. ftruncate($file, 0);
  92. fwrite($file, $array_happy);
  93. fclose($file);
  94. }
  95. function happyLog($userid,$torrentid, $multi)
  96. {
  97. $time = sqlesc(time());
  98. sql_query("INSERT INTO happylog (userid, torrentid,multi, date) VALUES($userid, $torrentid, $multi, $time)") or sqlerr(__FILE__, __LINE__);
  99. }
  100. ?>