PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/pluginz/download/4shared_com.php

http://rapidleech36b.googlecode.com/
PHP | 166 lines | 126 code | 29 blank | 11 comment | 37 complexity | 3b5279f8a2f6876dd342ba877275ffc9 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require_once ("index.html");
  4. exit();
  5. }
  6. class d4shared_com extends DownloadClass {
  7. private $page, $cookie, $pA;
  8. public $link;
  9. public function Download($link) {
  10. global $premium_acc;
  11. $this->cookie = array('4langcookie' => 'en');
  12. if (stristr($link, ".com/get/")) {
  13. $link = str_replace('.com/get/', '.com/file/', $link);
  14. }
  15. $this->link = $link;
  16. $this->page = $this->GetPage($this->link, $this->cookie);
  17. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  18. is_present($this->page, "The file link that you requested is not valid.");
  19. is_present($this->page, "The file is suspected of illegal or copyrighted content.");
  20. if ($_REQUEST["premium_acc"] == "on" && ((!empty($_REQUEST["premium_user"]) && !empty($_REQUEST["premium_pass"])) || ($premium_acc["4shared_com"]["user"] && $premium_acc["4shared_com"]["pass"]))) {
  21. $this->pA = (!empty($_REQUEST["premium_user"]) && !empty($_REQUEST["premium_pass"]) ? true : false);
  22. return $this->login();
  23. } else {
  24. return $this->FreeDownload();
  25. }
  26. }
  27. private function FreeDownload() {
  28. $this->CheckForPass();
  29. if (preg_match('@<a [^>]*href="(http://dc\d+\.4shared\.com/download/[^/]+/[^/|"]+)"[^>]*>.+Download Now.+</a>@i', $this->page, $DL)) {
  30. if (preg_match('/(?:\?|&)dirPwdVerified=(\w+)/i', $this->link, $pwd)) $DL[1] .= "&dirPwdVerified=" . $pwd[1];
  31. $FileName = urldecode(basename(parse_url($DL[1], PHP_URL_PATH)));
  32. $this->RedirectDownload($DL[1], $FileName, $this->cookie);
  33. return;
  34. }
  35. if (!preg_match('/.com\/[^\/]+\/([^\/]+)\/?(.*)/i', $this->link, $L)) html_error("Invalid link?");
  36. $this->page = $this->GetPage("http://www.4shared.com/get/{$L[1]}/{$L[2]}", $this->cookie);
  37. if (preg_match('/href=\'(http:\/\/dc[^\']+)\'[^>]*>Download file now/i', $this->page, $D)) {
  38. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  39. $dllink = $D[1];
  40. if (preg_match('/(?:\?|&)dirPwdVerified=(\w+)/i', $this->link, $pwd)) $dllink .= "&dirPwdVerified=" . $pwd[1];
  41. } else {
  42. is_present($this->page, "?err=not-logged\r\n", "You need to be logged in for download this file.");
  43. html_error("Download-link not found.");
  44. }
  45. $FileName = urldecode(basename(parse_url($dllink, PHP_URL_PATH)));
  46. if (!preg_match('/var c = (\d+)/', $this->page, $count)) html_error("Timer not found.");
  47. if ($count[1] <= 120) $this->CountDown($count[1]);
  48. else {
  49. $data = $this->DefaultParamArr($dllink, encrypt($this->cookie));
  50. $data['filename'] = urlencode($FileName);
  51. $data['host'] = $url["host"];
  52. $data['port'] = $url["port"];
  53. $data['path'] = urlencode($url["path"] . ($url["query"] ? "?" . $url["query"] : ""));
  54. $data['saveto'] = $_GET["path"];
  55. $this->JSCountdown($count[1], $data);
  56. }
  57. $this->RedirectDownload($dllink, $FileName, $this->cookie);
  58. }
  59. private function CheckForPass($predl=false) {
  60. global $PHP_SELF, $L;
  61. if (isset($_GET["step"]) && $_GET["step"] == "1") {
  62. $post = array();
  63. $post["userPass2"] = $_POST['userPass2'];
  64. $post["dsid"] = trim($_POST['dsid']);
  65. $this->page = $this->GetPage($this->link, $this->cookie, $post, $this->link);
  66. is_present($this->page, "Please enter a password to access this file", "The password you have entered is not valid.");
  67. } elseif (stristr($this->page, 'Please enter a password to access this file')) {
  68. echo "\n" . '<center><form name="dl_password" action="' . $PHP_SELF . '" method="post" >' . "\n";
  69. $data = $this->DefaultParamArr($this->link);
  70. $data['step'] = 1;
  71. $data['dsid'] = cut_str($this->page, 'name="dsid" value="', '"');
  72. foreach ($data as $name => $val) echo "<input type='hidden' name='$name' id='$name' value='$val' />\n";
  73. if ($predl) echo '<br /><input type="checkbox" name="premium_acc" id="premium_acc" onclick="javascript:var displ=this.checked?\'\':\'none\';document.getElementById(\'premiumblock\').style.display=displ;" ' . (!$pA ? 'checked="checked"' : '') . ' />&nbsp;' . $L->say['use_premix'] . '<br /><div id="premiumblock" style="display: none;"><br /><table width="150" border="0"><tr><td>' . $L->say['_uname'] . ':&nbsp;</td><td><input type="text" name="premium_user" id="premium_user" size="15" value="" /></td></tr><tr><td>' . $L->say['_pass'] . ':&nbsp;</td><td><input type="password" name="premium_pass" id="premium_pass" size="15" value="" /></td></tr></table></div><br />';
  74. echo '<h4>Enter password here: <input type="text" name="userPass2" id="filepass" size="13" />&nbsp;&nbsp;<input type="submit" onclick="return check()" value="Download File" /></h4>' . "\n";
  75. echo "<script type='text/javascript'>\nfunction check() {\nvar pass=document.getElementById('filepass');\nif (pass.value == '') { window.alert('You didn\'t enter the password'); return false; }\nelse { return true; }\n}\n</script>\n";
  76. echo "\n</form></center>\n</body>\n</html>";
  77. exit;
  78. }
  79. $this->cookie = GetCookiesArr($this->page, $this->cookie, true, array('', 'deleted', '""'));
  80. }
  81. private function PremiumDownload() {
  82. $this->page = $this->GetPage($this->link, $this->cookie);
  83. $this->CheckForPass(true);
  84. if (stripos($this->page, "\r\nContent-Length: 0\r\n") !== false) {
  85. is_notpresent($this->page, "\r\nLocation:", "Error: Direct link not found.");
  86. if (!preg_match('@Location: (http://dc\d+.4shared.com/download/[^\r|\n]+)@i', $this->page, $dl)) html_error("Error: Download-link not found 2.");
  87. } elseif (!preg_match('@type="text" value="(http://dc\d+.4shared.com/download/[^"]+)"@i', $this->page, $dl)) {
  88. html_error("Error: Download-link not found.");
  89. }
  90. $dllink = $dl[1];
  91. if (preg_match('/(?:\?|&)dirPwdVerified=(\w+)/i', $this->link, $pwd)) $dllink .= "&dirPwdVerified=" . $pwd[1];
  92. $FileName = urldecode(basename(parse_url($dllink, PHP_URL_PATH)));
  93. $this->RedirectDownload($dllink, $FileName, $this->cookie);
  94. }
  95. private function login() {
  96. global $premium_acc, $L;
  97. $email = ($this->pA ? $_REQUEST["premium_user"] : $premium_acc["4shared_com"]["user"]);
  98. $pass = ($this->pA ? $_REQUEST["premium_pass"] : $premium_acc["4shared_com"]["pass"]);
  99. if (empty($email) || empty($pass)) html_error("Login Failed: EMail or Password is empty. Please check login data.");
  100. $postURL = "http://www.4shared.com/login";
  101. $post["login"] = urlencode($email);
  102. $post["password"] = urlencode($pass);
  103. $post["remember"] = "false";
  104. $post["doNotRedirect"] = "true";
  105. $page = $this->GetPage($postURL, $this->cookie, $post, $postURL);
  106. $this->cookie = GetCookiesArr($page, $this->cookie, true, array('', 'deleted', '""'));
  107. is_present($page, "Invalid e-mail address or password", "Login Failed: Invalid Username/Email or Password.");
  108. if (stripos($page, '"ok":false') !== false && $err = cut_str($page, '"rejectReason":"', '"')) html_error("Login Failed: 4S says: '$err'.");
  109. if (empty($this->cookie['Login'])) html_error('Login Failed. Cookie "Login" not found.');
  110. if (empty($this->cookie['Password'])) html_error('Login Failed. Cookie "Password" not found.');
  111. // Chk Acc.
  112. $page = $this->GetPage("http://www.4shared.com/account/home.jsp", $this->cookie);
  113. $this->cookie = GetCookiesArr($page, $this->cookie, true, array('', 'deleted', '""'));
  114. $quota = cut_str($page, 'Bandwidth:', "</div>");
  115. if ($quota === false || !preg_match('/"quota(?:(?:usagebar" title=")|(?:count">))([\d|\.]+)% of ([\d|\.]+) (\w+)/i', $quota, $qm)) {
  116. $this->changeMesg($L->say['_retrieving'] . "<br /><b>Account isn\\\'t premium?</b><br />Using it as member.");
  117. $this->page = $this->GetPage($this->link, $this->cookie);
  118. return $this->FreeDownload();
  119. }
  120. $used = floatval($qm[1]);
  121. $total = floatval($qm[2]);
  122. // I have to check the BW... I will show it too :)
  123. $this->changeMesg($L->say['_retrieving'] . "<br />4S Premium Download<br />Bandwidth: $used% of $total {$qm[3]}.");
  124. if ($used >= 95) html_error("Bandwidth limit trigered: Bandwidth: $used% - Limit: 95%");
  125. return $this->PremiumDownload();
  126. }
  127. }
  128. //[21-Nov-2010] Rewritten by Th3-822 & Using some code from the 2shared plugin.
  129. //[26-Jan-2011] Fixed cookies for download pass-protected files. - Th3-822
  130. //[02-Apr-2011] Fixed error when downloading pass-protected files & Added 1 Error Msg. - Th3-822
  131. //[07-May-2011] Some edits to the plugin && Added Premium download support. - Th3-822
  132. //[25-Jul-2011] Using a function for longer link timelock at free download. -Th3-822
  133. //[12-Sep-2011] Fixed regex for get BW usage in Premium && Password in files can be skiped with '?dirPwdVerified=xxxxxxxx' in the url. -Th3-822
  134. //[15-Oct-2011] JSCountdown was added in DownloadClass.php... Removed declaration from plugin. - Th3-822
  135. //[21-Nov-2011] Fixed regexp for get dlink in FreeDL. - Th3-822
  136. //[23-Mar-2012] Added support for member (its needed for some links) & some changes & small fixes. - Th3-822
  137. ?>