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