Th3-822

[rapidleech][u] vk.com.php

Aug 30th, 2012
2,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.19 KB | None | 0 0
  1. <?php
  2.  
  3. // ** VK (ВКонтакте) Upload Plugin by Th3-822 **
  4. // Create a Application at http://vk.com/editapp?act=create
  5. // Select "Web Site" and add your rapidleech url and the base domain.
  6. // After creating the app, copy the Application ID and the Secret key. and add them at $app.
  7.  
  8. ######## Plugin's Info ########
  9. $app = array();
  10. $app['id'] = ''; //Application ID
  11. $app['secret'] = ''; //Application SecretKey
  12. $upload_audio_as_video = false; // Upload Audio files to "My Videos"...
  13. $upload_video_as_doc = false; // Upload original Video file as Doc (Limit 200 MB)...
  14. ########################
  15. if (empty($app['id']) || empty($app['secret'])) html_error('Application ID or SecretKey Empty. Please create a VK\'s app and add them at '.HOST_DIR.'upload/'.basename(__FILE__));
  16.  
  17. $not_done = true;
  18. $_GET['proxy'] = isset($proxy) ? $proxy : (isset($_GET['proxy']) ? $_GET['proxy'] : '');
  19.  
  20. $return_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?uploaded='.urlencode($_REQUEST['uploaded']).'&filename='.urlencode(base64_encode($lname));
  21. if (!empty($_GET['proxy'])) $return_url .= '&useuproxy=on&uproxy='.urlencode($_GET['proxy']);
  22. if (!empty($_REQUEST['pauth'])) $return_url .= '&upauth='.urlencode($pauth);
  23. if (!empty($_GET['save_style'])) $return_url .= '&save_style='.urlencode($_GET['save_style']);
  24. if (isset($_GET['auul'])) $return_url .= '&auul='.urlencode($_GET['auul']);
  25.  
  26. $fileExts = array(
  27.     'video' => array('avi', 'mp4', '3gp', 'mpg', 'mpeg', 'mov', 'flv', 'wmv'),
  28.     'audio' => array('mp3'),
  29.     'block' => array('exe', 'scr', 'msi', 'com', 'cmd', 'bat', 'reg', 'pif', 'vbs', 'js', 'hta') /* Block non allowed fileExts (List May Be Incomplete) */
  30. );
  31. // File Ext Check
  32. $fExt = (strpos($lname, '.') !== false) ? strtolower(substr(strrchr($lname, '.'), 1)) : '';
  33. $type = 'doc';
  34. foreach ($fileExts as $t => $exts) {
  35.     if (in_array($fExt, $exts)) {
  36.         $type = $t;
  37.         break;
  38.     }
  39. }
  40.  
  41. // Convert Upload Types
  42. if ($type == 'audio' && $upload_audio_as_video) $type = 'video';
  43. elseif ($type == 'video' && $upload_video_as_doc) $type = 'doc';
  44.  
  45. // Check Type Limits
  46. switch ($type) {
  47.     case 'block': html_error("This file ext. ($fExt) isn't allowed by VK.");
  48.     case 'audio':
  49.     case 'doc':
  50.         if ($fsize > 200*1024*1024) html_error("You only can upload '$type' files up to 200 MB.");
  51. }
  52.  
  53. // Check https support for login.
  54. $usecurl = $options['use_curl'] && extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_exec') ? true : false;
  55. $chttps = false;
  56. if ($usecurl) {
  57.     $cV = curl_version();
  58.     if (in_array('https', $cV['protocols'], true)) $chttps = true;
  59. }
  60. if (!extension_loaded('openssl') && !$chttps) html_error('You need to install/enable PHP\'s OpenSSL extension to support HTTPS connections.');
  61. elseif (!$chttps) $usecurl = false;
  62.  
  63. $auth_url = 'https://oauth.vk.com/authorize?client_id='.urlencode($app['id']).'&display=popup&scope=audio,video,docs,offline&response_type=code&redirect_uri='.urlencode($return_url);
  64.  
  65. if (empty($_REQUEST['code'])) {
  66.     echo "\n<script type='text/javascript'>document.location = '$auth_url';</script>\n<h1 style='text-align:center'>You are being redirected to VK's oauth dialog...</h1><div style='text-align:center'>It doesn't redirect?, Click <a href='$auth_url'>here</a>.</div>\n";
  67.     exit("</body>\n</html>");
  68. } else {
  69.     $not_done = false;
  70.  
  71.     // Auth
  72.     echo "<table style='width:600px;margin:auto;'>\n<tr><td align='center'>\n<div id='login' width='100%' align='center'>Authenticating</div>\n";
  73.  
  74.     $page = vk_GetPage('https://oauth.vk.com/access_token?client_id='.urlencode($app['id']).'&client_secret='.urlencode($app['secret']).'&code='.urlencode($_REQUEST['code']).'&redirect_uri='.urlencode($return_url));
  75.     $json = Get_Reply($page);
  76.     if (!empty($json['error']) && stripos($json['error'], 'REDIRECT_URI') === false) html_error("Auth Error: [{$json['error']}] ".(!empty($json['error_description'])?$json['error_description']:''));
  77.  
  78.     // Retrive upload ID
  79.     echo "<script type='text/javascript'>document.getElementById('login').style.display='none';</script>\n<div id='info' width='100%' align='center'>Preparing Upload</div>\n";
  80.  
  81.     sleep(1); // They have a limit of 3 Request/Second... Let's wait a second :D
  82.  
  83.     $data = array();
  84.     switch ($type) {
  85.         case 'video':
  86.             $data['method'] = 'video.save';
  87.             $data['name'] = $lname;
  88.             $data['description'] = 'Uploaded with Rapidleech';
  89.             // $data['is_private'] = '1'; // Uncomment for upload videos as private. (Not Sure Yet How It Does Work)
  90.             // $data['group_id'] = 1234567890; // ID of the community. (Positive Number)
  91.             break;
  92.         case 'audio':
  93.             $data['method'] = 'audio.getUploadServer';
  94.             break;
  95.         case 'doc':
  96.             $data['method'] = 'docs.getUploadServer';
  97.             // $data['group_id'] = 1234567890; // ID of the community. (Positive Number)
  98.             break;
  99.     }
  100.  
  101.     $upsrv = vk_doApiReq($data);
  102.     if (!empty($upsrv['error'])) {
  103.         if ($upsrv['error'] == '204') html_error('Your account is banned for uploading.');
  104.         html_error("{$data['method']} Error: [{$upsrv['error']['error_code']}] {$upsrv['error']['error_msg']}");
  105.     }
  106.  
  107.     $post = array();
  108.     $up_url = $upsrv['response']['upload_url'];
  109.  
  110.     // Uploading
  111.     echo "<script type='text/javascript'>document.getElementById('info').style.display='none';</script>\n";
  112.  
  113.     $url = parse_url($up_url);
  114.     $upfiles = upfile($url['host'], defport($url), $url['path'].($url['query'] ? '?'.$url['query'] : ''), '', '', $post, $lfile, $lname, ($type == 'video' ? 'video_file' : 'file'), '', $_GET['proxy'], $pauth, 0, $url['scheme']);
  115.  
  116.     // Upload Finished
  117.     echo "<script type='text/javascript'>document.getElementById('progressblock').style.display='none';</script>\n";
  118.  
  119.     is_page($upfiles);
  120.     $upres = Get_Reply($upfiles);
  121.     if (!empty($upres['error'])) {
  122.         if (is_array($upres['error'])) html_error("Upload $type Error: [{$upres['error']['error_code']}] " . $upres['error']['error_msg']);
  123.         else if ($type == 'doc' && $upres['error'] == 'unknown error' && in_array($fExt, array('zip', 'zipx', 'rar', 'rar5', 'tar', 'gz', '7z', 'cab'))) html_error("Upload $type Error: Possible Forbidden File Type Inside Compressed File.");
  124.         else html_error("Upload $type Error: " . $upres['error']);
  125.     }
  126.  
  127.     if ($type != 'video') {
  128.         sleep(1); // Let's wait another second :D
  129.  
  130.         $data = array();
  131.         switch ($type) {
  132.             case 'audio':
  133.                 $data['method'] = 'audio.save';
  134.                 $data['audio'] = $upres['audio'];
  135.                 $data['server'] = $upres['server'];
  136.                 $data['hash'] = $upres['hash'];
  137.                 break;
  138.             case 'doc':
  139.                 $data['method'] = 'docs.save';
  140.                 $data['file'] = $upres['file'];
  141.                 $data['tags'] = 'Rapidleech';
  142.                 break;
  143.         }
  144.         $rply = vk_doApiReq($data);
  145.  
  146.         if (!empty($rply['error'])) {
  147.             if (is_array($rply['error'])) html_error($data['method'] . " Error: [{$rply['error']['error_code']}] " . $rply['error']['error_msg']);
  148.             else html_error($data['method'] . ' Error: ' . $rply['error']);
  149.         }
  150.     }
  151.  
  152.     if ($type == 'video') {
  153.         if (!empty($upsrv['response']['vid'])) $download_link = 'https://vk.com/video' . $json['user_id'] . '_' . $upsrv['response']['vid'];
  154.         else html_error('Your video will appear in your VK account after a while.', 0);
  155.     }
  156.     elseif ($type == 'doc' && !empty($rply['response'][0]['did'])) $download_link = 'https://vk.com/doc' . $rply['response'][0]['owner_id'] . '_' . $rply['response'][0]['did'];
  157.     else html_error('Check your VK account for see your new uploaded file.', 0);
  158. }
  159.  
  160. function vk_doApiReq($data) {
  161.     global $app;
  162.     $data['api_id'] = $app['id'];
  163.     $data['format'] = 'json';
  164.     $data['v'] = '3.0';
  165.     $sig = '';
  166.     ksort($data);
  167.     foreach ($data as $k => $v) $sig .= "$k=$v";
  168.     $sig = md5($sig.$app['secret']);
  169.     $baseLink = 'https://api.vk.com/method/'.$data['method'].'?';
  170.     unset($k, $v, $data['method']);
  171.     return Get_Reply(vk_GetPage($baseLink . http_build_query($data) . "&sig=$sig&access_token=".$GLOBALS['json']['access_token']));
  172. }
  173.  
  174. function Get_Reply($page) {
  175.     if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.');
  176.     $json = substr($page, strpos($page, "\r\n\r\n") + 4);
  177.     $json = substr($json, strpos($json, '{'));$json = substr($json, 0, strrpos($json, '}') + 1);
  178.     $rply = json_decode($json, true);
  179.     if (!$rply || (is_array($rply) && count($rply) == 0)) html_error('Error getting json data.');
  180.     return $rply;
  181. }
  182.  
  183. function vk_GetPage($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $XMLRequest = 0) {
  184.     if (!$referer && !empty($GLOBALS['Referer'])) {
  185.         $referer = $GLOBALS['Referer'];
  186.     }
  187.  
  188.     if ($GLOBALS['usecurl']) {
  189.         if ($XMLRequest) $referer .= "\r\nX-Requested-With: XMLHttpRequest";
  190.         $page = cURL($link, $cookie, $post, $referer, $auth);
  191.     } else {
  192.         global $pauth;
  193.         $Url = parse_url($link);
  194.         $page = geturl($Url['host'], defport($Url), $Url['path'] . (!empty($Url['query']) ? '?' . $Url['query'] : ''), $referer, $cookie, $post, 0, !empty($_GET['proxy']) ? $_GET['proxy'] : '', $pauth, $auth, $Url['scheme'], 0, $XMLRequest);
  195.         is_page($page);
  196.     }
  197.     return $page;
  198. }
  199.  
  200. //[30-8-2012] Written by Th3-822.
  201. //[28-10-2012] Small fixes that i don't remember. - Th3-822
  202. //[24-11-2012] Now it shows video url & Fixed auul for this plugin. - Th3-822
  203. //[22-9-2013] Fixed mp3 upload & Other issues. - Th3-822
  204. //[15-12-2014] Fixed uploading (Now it requires support for HTTPS uploads). - Th3-822
  205. //[23-8-2015] Added Docs upload support. - Th3-822
  206.  
  207. ?>
Add Comment
Please, Sign In to add comment