count = 0; $link = $this->ValidateURL($link); if (!$link) html_error('Invalid Link'); $this->link = $link; //$this->debug = true; // Uncomment to enable debug info. } public function MassConvert($methods) { foreach(array_filter(explode(' ', $methods)) as $method) { if ($this->count > 3) return; $this->Convert($method); } } public function Convert($method, $opts = null) { if ($this->count > 3) return false; $func = array($this, "lnk_$method"); try { if (!is_callable($func)) throw new Exception(__CLASS__."::lnk_$method is not callable."); if (!($convertedLink = call_user_func($func, $opts))) return false; $this->link = $convertedLink; } catch (Exception $e) { $GLOBALS['throwRLErrors'] = false; // Disable throw on error in case of a cURL error. if ($this->debug) { textarea($e); // Debug //textarea(var_export($e, true)); // Debug | Extra info } return false; } $this->count++; } public function GetLink() { return $this->link; } protected function ValidateURL($link) { if (empty($link)) return false; $link = filter_var($link, FILTER_SANITIZE_URL); if (filter_var($link, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_PATH_REQUIRED) && in_array(strtolower(parse_url($link, PHP_URL_SCHEME)), array('http', 'https', 'ftp'))) return $link; else return false; } protected function Request($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $opts = 0) { if (!empty($post) && is_array($post)) $post = http_build_query($post, '', '&'); $timeouts = array(); $timeouts[CURLOPT_FAILONERROR] = (!$this->debug); // Fail on errors $timeouts[CURLOPT_CONNECTTIMEOUT] = 10; // Connection Timeout $timeouts[CURLOPT_TIMEOUT] = 10; // Page Timeout if (is_array($opts)) $opts = array_merge($opts, $timeouts); else $opts = $timeouts; $GLOBALS['throwRLErrors'] = true; // Throw errors. $page = cURL($link, $cookie, $post, $referer, $auth, $opts); $GLOBALS['throwRLErrors'] = false; // Disable throw on error. // Debug if ($this->debug) { $debug = "Request: $link"; if (!empty($referer)) $debug .= "\nReferer: " . str_replace(array("\r", "\n"), array('\r', '\n'), $referer); if (!empty($_GET['useproxy']) && $_GET['useproxy'] == 'on' && !empty($_GET['proxy'])) $debug .= "\nProxy Enabled\nProxy: " . $_GET['proxy']; if (!empty($cookie)) $debug .= "\nCookie: ".(is_array($cookie) ? substr(print_r($cookie, true), 0, -1) : trim($cookie)); if ($auth) $debug .= "\nAuth: ".base64_decode($auth); if ($post != '0') $debug .= "\nPOST: ".(is_array($post) ? substr(print_r($post, true), 0, -1) : $post); textarea("$debug\n-----\n".preg_replace('@([^\r])\n@', '$1\n'."\n", str_replace("\r\n", '\r\n'."\r\n", substr($page, 0, strpos($page, "\r\n\r\n")+4))).(strpos($page, chr(0)) === false ? substr($page, strpos($page, "\r\n\r\n")+4) : '[Binary Content?]'),200,15); } return $page; } protected function GetBody($page) { return (($pos = strpos($page, "\r\n\r\n")) > 0) ? substr($page, $pos + 4) : $page; } protected function json2array($content) { if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.'); if (empty($content)) return NULL; $content = ltrim($content); if (($pos = strpos($content, "\r\n\r\n")) > 0) $content = trim(substr($content, $pos + 4)); $cb_pos = strpos($content, '{'); $sb_pos = strpos($content, '['); if ($cb_pos === false && $sb_pos === false) throw new Exception('Json start braces not found.'); $sb = ($cb_pos === false || $sb_pos < $cb_pos) ? true : false; $content = substr($content, strpos($content, ($sb ? '[' : '{')));$content = substr($content, 0, strrpos($content, ($sb ? ']' : '}')) + 1); if (empty($content)) throw new Exception('No json content.'); $rply = json_decode($content, true); if ($rply === NULL) throw new Exception('Error reading json.'); return $rply; } protected function chkHttpsSupport() { if ($this->https) return true; $cV = curl_version(); return $this->https = in_array('https', $cV['protocols'], true); } // Add Methods Here: (prefixed with 'lnk_') protected function lnk_adfly($opts = null) { $options = array( // https://adf.ly/publisher/tools#tools-api 'key' => '1d7528f24a09dbd0339860c6a1cf9a22', /* Your ApiKey */ 'uid' => '10221009', /* Your UserId */ 'advert_type' => 'int', /* 'int' or 'banner' */ 'domain' => 'adf.ly' /* 'adf.ly', 'j.gs', 'q.gs' or 'your custom domain' */ ); if (!is_null($opts) && is_array($opts)) $options = array_merge($options, $opts); if (empty($options['key']) || empty($options['uid'])) return false; $options['url'] = $this->link; $body = $this->GetBody($this->Request('http://api.adf.ly/api.php?'.http_build_query($options, '', '&'))); return $this->ValidateURL($body); } protected function lnk_bcvc($opts = null) { $options = array( // http://bc.vc/tools.php?api 'key' => '1a708a7090a08c94e36b63cbf1de97cc', /* Your ApiKey */ 'uid' => '109189' /* Your UserId */ ); if (!is_null($opts) && is_array($opts)) $options = array_merge($options, $opts); if (empty($options['key']) || empty($options['uid'])) return false; $options['url'] = $this->link; $x = 0; do { $body = $this->GetBody($this->Request('http://bc.vc/api.php?'.http_build_query($options, '', '&'))); $x++; } while (!empty($body) && $x < 3 && stripos($body, 'Unable to connect to database') !== false); return $this->ValidateURL($body); } protected function lnk_linkbucks($opts = null) { if (!function_exists('json_encode')) html_error('Error: Please enable JSON in php.'); if (!$this->chkHttpsSupport()) html_error('Your cURL doesn\'t support https connections.'); $options = array( // https://www.linkbucks.com/Profile 'user' => 'Th3822', /* Your UserName */ 'apiPassword' => '23c02a93e403480b', /* Your ApiKey (Secret) */ 'adType' => 2, /* 2 = Ads ($) | 5 = No Ads (No $) */ 'contentType' => 1, /* 1: Clean | 2: Adult Content */ 'domain' => 'linkbucks.com' /* Alias Domain, full list is at https://www.linkbucks.com/CreateLinks/Single/ */ ); if (!is_null($opts) && is_array($opts)) $options = array_merge($options, $opts); if (empty($options['user']) || empty($options['apiPassword'])) return false; $options['originalLink'] = $this->link; $json = $this->json2array($this->Request('https://www.linkbucks.com/api/createLink/single', 0, json_encode($options))); // Alternate domain that supports API: www.linkbucksmedia.com return (!empty($json['link']) ? $this->ValidateURL($json['link']) : false); } protected function lnk_shortest($opts = null) { if (!$this->chkHttpsSupport()) html_error('Your cURL doesn\'t support https connections.'); $options = array( // https://shorte.st/es/tools/api 'key' => '567b51cd25df5567eb48709142876afd' /* Your ApiKey */ ); if (!is_null($opts) && is_array($opts)) $options = array_merge($options, $opts); if (empty($options['key'])) return false; $json = $this->json2array($this->Request('https://api.shorte.st/v1/data/url', 0, array('urlToShorten' => $this->link), "\r\nX-HTTP-Method-Override: PUT\r\nPublic-Api-Token: " . $options['key'])); return (!empty($json['shortenedUrl']) ? str_ireplace('http://', 'https://', $this->ValidateURL($json['shortenedUrl'])) : false); } // Evilest shortener, annoys users with captchas. protected function lnk_ouoio($opts = null) { $options = array( // http://ouo.io/manage/tools/quick-link 'key' => 'IsYbNk1X' /* Your ApiKey */ ); if (!is_null($opts) && is_array($opts)) $options = array_merge($options, $opts); if (empty($options['key'])) return false; $body = $this->GetBody($this->Request("http://ouo.io/api/{$options['key']}?s=" . urlencode($this->link))); return $this->ValidateURL($body); } protected function lnk_ppw($opts = null) { $options = array( // http://p.pw/publisher/tools.php 'user' => '382635' /* Your UserId */ ); if (!is_null($opts) && is_array($opts)) $options = array_merge($options, $opts); if (empty($options['user'])) return false; $options['url'] = $this->link; $json = $this->json2array($this->Request('http://p.pw/API/write/get?' . http_build_query($options, '', '&'))); return ((!empty($json['success']) && !empty($json['data']['url'])) ? $this->ValidateURL($json['data']['url']) : false); } } if (empty($_GET['path']) && empty($_GET['sha'])) { // Redirect to index.php when called without query. $Path = strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/'); if (empty($Path) || $Path == '.' || $Path == '/') $Path = ''; else $Path = (substr($Path, 0, 1) == '/' ? $Path : "/$Path"); $Path .= "/index.php"; header("Location: $Path"); exit; } elseif (empty($_GET['path']) || empty($_GET['sha'])) html_error('Invalid download-link.'); $path = decrypt(base64_decode($_GET['path'])); if (sha1($path) != $_GET['sha']) html_error('Corrupted download-link.'); $path = strtr((in_array(substr($path, 0, 1), array('/', '\\')) ? $path : "/$path"), '\\', '/'); // Add start / to path and replace any backslash with a slash $link = 'http://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']) . $path; $shortener = new LinkConverter($link); // Call Converters Here //$shortener->MassConvert('adfly bcvc linkbucks shortest ouoio ppw'); //$shortener->Convert('ppw'); // Get Final Converted Link $newLink = $shortener->GetLink(); if (headers_sent($filename, $line)) { // Show Error Message and Link to Continue. html_error('Headers Sent by: '.htmlspecialchars($filename).' @ Line #'.$line.'
Click Here to Continue'); } else { // Do Redirect header("Location: $newLink", true, 301); exit; } // Written by Th3-822 // Last Updated: 10/2/2017 // Added p.pw support