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

/pluginz/DownloadClass.php

http://rapidleech36b.googlecode.com/
PHP | 273 lines | 257 code | 3 blank | 13 comment | 13 complexity | bc66287cd50ebd77815122bbb6ce73a4 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require('../404.php');
  4. exit;
  5. }
  6. class DownloadClass {
  7. /*
  8. * Prints the initial form for displaying messages
  9. *
  10. * @return void
  11. */
  12. public function __construct() {
  13. global $L;
  14. echo('<table width="600" align="center">');
  15. echo('<tr>');
  16. echo('<td align="center">');
  17. echo('<div id="mesg" width="100%" align="center">' . $L->say['_retrieving'] . '</div>');
  18. }
  19. /**
  20. * You can use this function to retrieve pages without parsing the link
  21. * @param string $link The link of the page to retrieve
  22. * @param string $cookie The cookie value if you need
  23. * @param array $post name=>value of the post data
  24. * @param string $referer The referer of the page, it might be the value you are missing if you can't get plugin to work
  25. * @param string $auth Page authentication, unneeded in most circumstances
  26. */
  27. public function GetPage($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $XMLRequest=0) {
  28. global $options;
  29. if (!$referer) {
  30. global $Referer;
  31. $referer = $Referer;
  32. }
  33. $cURL = $options['use_curl'] && (extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_exec')) ? true : false;
  34. $Url = parse_url(trim($link));
  35. if ($Url ["scheme"] == 'https') {
  36. $chttps = false;
  37. if ($cURL) {
  38. $cV = curl_version();
  39. if (in_array('https', $cV['protocols'], true)) $chttps = true;
  40. }
  41. if (!extension_loaded('openssl') && !$chttps) html_error("This server doesn't support https connections.");
  42. elseif (!$chttps) $cURL = false;
  43. }
  44. if ($cURL) {
  45. if ($XMLRequest) $referer .= "\r\nX-Requested-With: XMLHttpRequest";
  46. $page = cURL($link, $cookie, $post, $referer, $auth);
  47. } else {
  48. global $pauth;
  49. $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);
  50. is_page($page);
  51. }
  52. return $page;
  53. }
  54. /*
  55. * Use this function instead of insert_location so that we can improve this feature in the future
  56. * @param string $link -> The download link of the file
  57. * @param string $FileName -> The name of the file
  58. * @param string $cookie -> The cookie value
  59. * @param array $post -> The post value will be serialized here
  60. * @param string $referer -> The page that refered to this link
  61. * @param string $auth -> In format username:password
  62. * @param array $params -> This parameter allows you to add extra _GET values to be passed on
  63. */
  64. public function RedirectDownload($link, $FileName, $cookie = 0, $post = 0, $referer = 0, $force_name = 0, $auth = "", $params = array()) {
  65. global $pauth;
  66. if (!$referer) {
  67. global $Referer;
  68. $referer = $Referer;
  69. }
  70. $Url = parse_url($link);
  71. //if (substr($auth,0,6) != "&auth=") $auth = "&auth=" . $auth;
  72. if (is_array($cookie)) {
  73. $cookie = CookiesToStr($cookie);
  74. }
  75. if (!is_array($params)) {
  76. // Some problems with the plugin, quit it
  77. html_error('Plugin problem! Please report, error: "The parameter passed must be an array"');
  78. }
  79. $addon = "";
  80. if (count((array) $params) > 0) {
  81. foreach ($params as $name => $value) {
  82. if (is_array($value)) {
  83. $value = serialize($value);
  84. }
  85. $addon .= '&' . $name . '=' . urlencode($value) . '&';
  86. }
  87. $addon = substr($addon, 0, -1);
  88. }
  89. $loc = "{$_SERVER['PHP_SELF']}?filename=" . urlencode($FileName) .
  90. "&host=" . $Url ["host"] . "&port=" . (isset($Url ["port"]) ? $Url ["port"] : '') . "&path=" .
  91. urlencode($Url ["path"] . (!empty($Url ["query"]) ? "?" . $Url ["query"] : "")) .
  92. "&referer=" . urlencode($referer) . "&email=" . (!empty($_GET ["domail"]) ? $_GET ["email"] : "") .
  93. "&partSize=" . (!empty($_GET ["split"]) ? $_GET ["partSize"] : "") . "&method=" . (!empty($_GET ["method"]) ? $_GET ["method"] : '') .
  94. (!empty($_GET ["proxy"]) ? "&useproxy=on&proxy=" . $_GET ["proxy"] : "") . "&saveto=" . $_GET ["path"] .
  95. "&link=" . urlencode($link) . (isset($_GET ["add_comment"]) && $_GET ["add_comment"] == "on" && !empty($_GET ["comment"]) ? "&comment=" .
  96. urlencode($_GET ["comment"]) : "") . ($auth ? '&auth=' . ($auth == 1 ? 1 : urlencode($auth)) : "") . ($pauth ? "&pauth=$pauth" : "") .
  97. (!empty($_GET ["uploadlater"]) && !empty($_GET['uploadtohost']) ? "&uploadlater=" . $_GET["uploadlater"] . "&uploadtohost=" . $_GET['uploadtohost'] : "") .
  98. "&cookie=" . ($cookie ? urlencode(encrypt($cookie)) : "") .
  99. "&post=" . ($post ? urlencode(serialize($post)) : "") .
  100. (isset($_POST ['autoclose']) ? "&autoclose=1" : "") .
  101. (isset($_GET["idx"]) ? "&idx=" . $_GET["idx"] : "") . $addon;
  102. if ($force_name) {
  103. $loc = $loc . "&force_name=" . urlencode($force_name);
  104. }
  105. insert_location($loc);
  106. }
  107. /*
  108. * Use this function to move your multiples links array to auto downloader
  109. * @param array $link_array -> Normal array containing all download links
  110. */
  111. public function moveToAutoDownloader($link_array) {
  112. global $nn, $options;
  113. if (count($link_array) == 0) {
  114. html_error('Error getting links from folder.');
  115. }
  116. if (!is_file("audl.php") || isset($options['forbid']['_audl'])) {
  117. html_error('audl.php not found or you have disable auto download feature!');
  118. }
  119. $links = "";
  120. foreach ($link_array as $key => $value) {
  121. $links .= $value . $nn;
  122. }
  123. echo "<form action='audl.php?GO=GO' method='post' >\n";
  124. echo "<input type='hidden' name='links' value='" . $links . "'>\n";
  125. $key_array = array("useproxy", "proxy", "proxyuser", "proxypass");
  126. foreach ($key_array as $v)
  127. if (isset($_GET [$v])) echo "<input type='hidden' name='" . $v . "' value='" . $_GET [$v] . "' >\n";
  128. echo "<script language='JavaScript'>void(document.forms[0].submit());</script>\n";
  129. echo "</form>\n";
  130. flush();
  131. exit();
  132. }
  133. public function CountDown($countDown) {
  134. insert_timer($countDown, "Waiting link timelock");
  135. }
  136. /*
  137. * Use this function to create Captcha display form
  138. * @param string $captchaImg -> The link of the captcha image or downloaded captcha image on server
  139. * @param array $inputs -> Key Value pairs for html form input elements ( these elements will be hidden form elements )
  140. * @param string $captchaSize -> The size of captcha text box
  141. */
  142. public function EnterCaptcha($captchaImg, $inputs, $captchaSize = '5') {
  143. global $L;
  144. echo "\n";
  145. echo('<form name="dl" action="' . $_SERVER['PHP_SELF'] . '" method="post">');
  146. echo "\n";
  147. foreach ($inputs as $name => $input) {
  148. echo('<input type="hidden" name="' . $name . '" id="' . $name . '" value="' . $input . '" />');
  149. echo "\n";
  150. }
  151. echo('<h4>' . $L->say['_enter'] . ' <img src="' . $captchaImg . '" /> ' . $L->say['_here'] . ': <input type="text" name="captcha" size="' . $captchaSize . '" />&nbsp;&nbsp;');
  152. echo "\n";
  153. echo( '<input type="submit" onclick="return check();" value="Enter Captcha" /></h4>');
  154. echo "\n";
  155. echo('<script type="text/javascript">');
  156. echo "\n";
  157. echo('function check() {');
  158. echo "\n";
  159. echo('var captcha=document.dl.captcha.value;');
  160. echo "\n";
  161. echo('if (captcha == "") { window.alert("You didn\'t enter the image verification code"); return false; }');
  162. echo "\n";
  163. echo('else { return true; }');
  164. echo "\n";
  165. echo('}');
  166. echo "\n";
  167. echo('</script>');
  168. echo "\n";
  169. echo('</form>');
  170. echo "\n";
  171. echo('</body>');
  172. echo "\n";
  173. echo('</html>');
  174. }
  175. /*
  176. * This function will return a array with the Default Key Value pairs including proxy, method, email, etc.
  177. * @param string $link -> Adds the link value to the array url encoded if you need it.
  178. * @param string $cookie -> Adds the cookie value to the array url encoded if you need it.
  179. * @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.)
  180. */
  181. public function DefaultParamArr($link = 0, $cookie = 0, $referer = 1) {
  182. if ($referer == 1) {
  183. global $Referer;
  184. $referer = $Referer;
  185. }
  186. if (is_array($cookie)) {
  187. $cookie = CookiesToStr($cookie);
  188. }
  189. $DParam = array();
  190. if ($link) $DParam['link'] = urlencode($link);
  191. if ($cookie) $DParam['cookie'] = urlencode($cookie);
  192. if ($referer) $DParam['referer'] = urlencode($referer);
  193. if (isset($_GET ["useproxy"]) && $_GET ["useproxy"] == 'on' && !empty($_GET ["proxy"])) {
  194. global $pauth;
  195. $DParam["useproxy"] = 'on';
  196. $DParam["proxy"] = $_GET ["proxy"];
  197. if ($pauth) $DParam["pauth"] = $pauth;
  198. }
  199. if (isset($_GET["autoclose"])) $DParam["autoclose"] = 1;
  200. if (isset($_GET["idx"])) $DParam["idx"] = $_GET["idx"];
  201. $params = array("add_comment", "domail", "comment", "email", "split", "partSize", "method", "uploadlater", "uploadtohost");
  202. foreach ($params as $key) if (!empty($_GET [$key])) $DParam[$key] = $_GET [$key];
  203. return $DParam;
  204. }
  205. /*
  206. * Use this function for filehost longer timelock
  207. * Param int $secs -> The number of seconds to count down
  208. * Param array $post -> Variable array to include as POST so you dont need to start over the process
  209. * Param $string $text -> Default text you want to display when counting down
  210. */
  211. public function JSCountdown($secs, $post = 0, $text='Waiting link timelock', $stop = 1) {
  212. global $PHP_SELF;
  213. 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";
  214. echo "<form action='$PHP_SELF' name='cdwait' method='POST'>\n";
  215. if ($post) {
  216. foreach ($post as $name => $input) {
  217. echo "<input type='hidden' name='$name' id='$name' value='$input' />\n";
  218. }
  219. }
  220. echo '<script type="text/javascript">';
  221. echo 'var c = '.$secs.';var text = "'.$text.'";var c2 = 0;var dl = document.getElementById("dl");var a2 = document.getElementById("dl2");fc();fc2();';
  222. echo "function fc() {";
  223. echo "if (c > 0) {";
  224. echo "if (c > 120) {";
  225. echo 'dl.innerHTML = text+". Please wait <b>"+ Math.round(c/60) +"</b> minutes...";';
  226. echo "} else {";
  227. echo 'dl.innerHTML = text+". Please wait <b>"+c+"</b> seconds...";';
  228. echo "}";
  229. echo "c = c - 1;";
  230. echo 'setTimeout("fc()", 1000);';
  231. echo "} else {";
  232. echo 'dl.style.display="none";';
  233. echo 'void(';
  234. if ($post) {
  235. echo 'document.forms.cdwait.submit()';
  236. } else {
  237. echo 'location.reload()';
  238. }
  239. echo ");";
  240. echo "}";
  241. echo "}";
  242. echo '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"}}';
  243. echo "</script></form><br />";
  244. if ($stop) exit("</body></html>");
  245. }
  246. public function changeMesg($mesg) {
  247. echo('<script>document.getElementById(\'mesg\').innerHTML=\'' . stripslashes($mesg) . '\';</script>');
  248. }
  249. }
  250. ?>