PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hosts/DownloadClass.php

http://rapidleech.googlecode.com/
PHP | 207 lines | 129 code | 23 blank | 55 comment | 44 complexity | 820daff45405d5f0e0f25e406b59ca58 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require('../deny.php');
  4. exit;
  5. }
  6. class DownloadClass {
  7. /*
  8. * Prints the initial form for displaying messages
  9. * @return void
  10. */
  11. public function __construct() {
  12. echo('<table width="600" align="center">');
  13. echo('<tr>');
  14. echo('<td align="center">');
  15. echo('<div id="mesg" width="100%" align="center">' . lang(300) . '</div>');
  16. }
  17. /*
  18. * You can use this function to retrieve pages without parsing the link
  19. * @param string $link -> The link of the page to retrieve
  20. * @param string $cookie -> The cookie value if you need
  21. * @param array $post -> Array name=>value of the post data
  22. * @param string $referer -> The referer of the page, it might be the value you are missing if you can't get plugin to work
  23. * @param string $auth -> Page authentication, unneeded in most circumstances
  24. */
  25. public function GetPage($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $XMLRequest = 0) {
  26. global $options;
  27. if (!$referer) {
  28. global $Referer;
  29. $referer = $Referer;
  30. }
  31. $cURL = ($options['use_curl'] && extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_exec')) ? true : false;
  32. $Url = parse_url(trim($link));
  33. if ($Url ['scheme'] == 'https') {
  34. $chttps = false;
  35. if ($cURL) {
  36. $cV = curl_version();
  37. if (in_array('https', $cV['protocols'], true)) $chttps = true;
  38. }
  39. if (!extension_loaded('openssl') && !$chttps) html_error('This server doesn\'t support https connections.');
  40. elseif (!$chttps) $cURL = false;
  41. }
  42. if ($cURL) {
  43. if ($XMLRequest) $referer .= "\r\nX-Requested-With: XMLHttpRequest";
  44. $page = cURL($link, $cookie, $post, $referer, $auth);
  45. } else {
  46. global $pauth;
  47. $page = geturl($Url ['host'], !empty($Url ['port']) ? $Url ['port'] : 80, $Url ['path'] . (!empty($Url ['query']) ? '?' . $Url ['query'] : ''), $referer, $cookie, $post, 0, !empty($_GET ['proxy']) ? $_GET ['proxy'] : '', $pauth, $auth, $Url ['scheme'], 0, $XMLRequest);
  48. is_page($page);
  49. }
  50. return $page;
  51. }
  52. /*
  53. * Use this function instead of insert_location so that we can improve this feature in the future
  54. * @param string $link -> The download link of the file
  55. * @param string $FileName -> The name of the file
  56. * @param string $cookie -> The cookie value
  57. * @param array $post -> The post value will be serialized here
  58. * @param string $referer -> The page that refered to this link
  59. * @param string $auth -> In format username:password
  60. * @param array $params -> This parameter allows you to add extra _GET values to be passed on
  61. */
  62. public function RedirectDownload($link, $FileName, $cookie = 0, $post = 0, $referer = 0, $force_name = 0, $auth = 0, $addon = array()) {
  63. global $pauth;
  64. if (!$referer) {
  65. global $Referer;
  66. $referer = $Referer;
  67. }
  68. $url = parse_url($link);
  69. $params = $this->DefaultParamArr($link, (!empty($cookie) ? (is_array($cookie) ? encrypt(CookiesToStr($cookie)) : encrypt($cookie)) : 0), $referer);
  70. $params['filename'] = urlencode($FileName);
  71. if (!empty($force_name)) $params['force_name'] = urlencode($force_name);
  72. $params['host'] = urlencode($url['host']);
  73. if (!empty($url['port'])) $params['port'] = urlencode($url['port']);
  74. $params['path'] = urlencode($url['path'] . (!empty($url['query']) ? '?' . $url['query'] : ''));
  75. if (!empty($post)) $params['post'] = encrypt(serialize($post));
  76. if (!empty($auth)) $params['auth'] = ($auth == 1 ? 1 : urlencode($auth));
  77. if (!empty($addon)) {
  78. if (!is_array($addon)) html_error('Plugin problem! Please report, error: "The parameter passed must be an array"'); // Some problems with the plugin, quit it
  79. foreach ($addon as $name => $value) $params[$name] = (is_array($value) ? urlencode(serialize($value)) : urlencode($value));
  80. }
  81. insert_location($params);
  82. }
  83. /*
  84. * Use this function to move your multiples links array to auto downloader
  85. * @param array $link_array -> Normal array containing all download links
  86. */
  87. public function moveToAutoDownloader($link_array) {
  88. global $PHP_SELF, $options;
  89. if (empty($link_array) || !is_array($link_array) || count($link_array) == 0) html_error('Error getting links from folder.');
  90. if (!is_file('audl.php') || !empty($options['auto_download_disable'])) html_error('audl.php not found or you have disable auto download feature!');
  91. $pos = strrpos($PHP_SELF, '/');
  92. $audlpath = ($pos !== false) ? substr($PHP_SELF, 0, $pos + 1).'audl.php?GO=GO' : 'audl.php?GO=GO';
  93. $inputs = GetDefaultParams();
  94. $inputs['links'] = implode("\r\n", $link_array);
  95. $key_array = array('premium_acc', 'premium_user', 'premium_pass', 'cookieuse', 'cookie');
  96. foreach ($key_array as $v) if (!empty($_GET[$v])) $inputs[$v] = urlencode($_GET[$v]);
  97. insert_location($inputs, $audlpath);
  98. exit();
  99. }
  100. public function CountDown($countDown) {
  101. insert_timer($countDown, "Waiting link timelock");
  102. }
  103. /*
  104. * Use this function to create Captcha display form
  105. * @param string $captchaImg -> The link of the captcha image or downloaded captcha image on server
  106. * @param array $inputs -> Key Value pairs for html form input elements ( these elements will be hidden form elements )
  107. * @param string $captchaSize -> The size of captcha text box
  108. */
  109. public function EnterCaptcha($captchaImg, $inputs, $captchaSize = '5') {
  110. echo "\n<form name='dl' action='{$_SERVER['SCRIPT_NAME']}' method='POST'>\n";
  111. foreach ($inputs as $name => $input) echo "\t<input type='hidden' name='$name' id='$name' value='$input' />\n";
  112. echo "\t<h4>" . lang(301) . " <img alt='CAPTCHA Image' src='$captchaImg' /> " . lang(302) . ": <input type='text' name='captcha' size='$captchaSize' />&nbsp;&nbsp;\n\t\t<input type='submit' onclick='return check();' value='Enter Captcha' />\n\t</h4>\n";
  113. echo "<script type='text/javascript'>\n\tfunction check() {\n\t\tvar captcha=document.dl.captcha.value;\n\t\tif (captcha == '') {\n\t\t\twindow.alert('You didn\'t enter the image verification code');\n\t\t\treturn false;\n\t\t} else return true;\n\t}\n</script>";
  114. echo "</form>\n</body\n</html>";
  115. }
  116. /*
  117. * This function will return a array with the Default Key Value pairs including proxy, method, email, etc.
  118. * @param string $link -> Adds the link value to the array url encoded if you need it.
  119. * @param string $cookie -> Adds the cookie value to the array url encoded if you need it.
  120. * @param string $referer -> Adds the referer value to the array url encoded if you need it. If isn't set, it will load $Referer value. (Set as 0 or false for don't add it in the array.)
  121. */
  122. public function DefaultParamArr($link = 0, $cookie = 0, $referer = 1) {
  123. if ($referer == 1) {
  124. global $Referer;
  125. $referer = $Referer;
  126. }
  127. if (is_array($cookie)) $cookie = CookiesToStr($cookie);
  128. $DParam = GetDefaultParams();
  129. if ($link) $DParam['link'] = urlencode($link);
  130. if ($cookie) $DParam['cookie'] = urlencode($cookie);
  131. if ($referer) $DParam['referer'] = urlencode($referer);
  132. return $DParam;
  133. }
  134. /* Use this function for filehost longer timelock
  135. * Param int $secs -> The number of seconds to count down
  136. * Param array $post -> Variable array to include as POST so you dont need to start over the process
  137. * Param $string $text -> Default text you want to display when counting down
  138. */
  139. public function JSCountdown($secs, $post = 0, $text='Waiting link timelock', $stop = 1) {
  140. global $PHP_SELF;
  141. echo "<p><center><span id='dl' class='htmlerror'><b>ERROR: Please enable JavaScript. (Countdown)</b></span><br /><span id='dl2'>Please wait</span></center></p>\n";
  142. echo "<form action='$PHP_SELF' name='cdwait' method='POST'>\n";
  143. if ($post) {
  144. foreach ($post as $name => $input) {
  145. echo "<input type='hidden' name='$name' id='$name' value='$input' />\n";
  146. }
  147. }
  148. ?> <script type="text/javascript">
  149. var c = <?php echo $secs; ?>;var text = "<?php echo $text; ?>";var c2 = 0;var dl = document.getElementById("dl");var a2 = document.getElementById("dl2");fc();fc2();
  150. function fc() {
  151. if (c > 0) {
  152. if (c > 120) {
  153. dl.innerHTML = text+". Please wait <b>"+ Math.round(c/60) +"</b> minutes...";
  154. } else {
  155. dl.innerHTML = text+". Please wait <b>"+c+"</b> seconds...";
  156. }
  157. c = c - 1;
  158. setTimeout("fc()", 1000);
  159. } else {
  160. dl.style.display="none";
  161. void(<?php if ($post) echo 'document.forms.cdwait.submit()';else echo 'location.reload()'; ?>);
  162. }
  163. }
  164. function fc2(){if(c>120){if(c2<=20){a2.innerHTML=a2.innerHTML+".";c2=c2+1}else{c2=10;a2.innerHTML=""}setTimeout("fc2()",100)}else{dl2.style.display="none"}}<?php
  165. echo "</script></form><br />";
  166. if ($stop) exit("</body></html>");
  167. }
  168. public function changeMesg($mesg) {
  169. echo('<script>document.getElementById(\'mesg\').innerHTML=\'' . stripslashes($mesg) . '\';</script>');
  170. }
  171. }
  172. /**********************************************************
  173. Added support of force_name in RedirectDownload function by Raj Malhotra on 02 May 2010
  174. Fixed EnterCaptcha function ( Re-Write ) by Raj Malhotra on 16 May 2010
  175. Added auto-encryption system (szal) 14 June 2010
  176. Added GetPage support function for https connection by Th3-822 21 April 2011
  177. Added GetPage support function for xml request by vdhdevil 9 July 2011
  178. Tweaked DefaultParamArr code by Th3-822 22 July 2011
  179. Moved JSCountdown function for future use by Th3-822
  180. Add CheckBack function to test correctly download link by vdhdevil
  181. Remove declaration of checkback function, it automatically signed in the plugin itself
  182. Add new limitation options by Ruud v.Tony
  183. **********************************************************/
  184. ?>