fork download
  1. <?php
  2. header("Content-type: text/html; charset=utf8");
  3. set_time_limit(60000*60);
  4. error_reporting(E_ERROR);
  5. if(!isset($_SESSION['youtube_pro_user']) OR $_SESSION['super_admin'] == 0) {
  6. header("location:login.php");
  7. }
  8. include('../include/config.php');
  9. include('../include/connect.php');
  10. include('include/functions.php');
  11. include('include/general.class.php');
  12. $general = new General;
  13. $general->set_connection($mysqli);
  14. $options = $general->get_all_options();
  15. $case = make_safe(xss_clean($_GET['case']));
  16. $action = make_safe(xss_clean($_POST['action']));
  17. if ($action == "sort_category"){
  18. $records = $_POST['records'];
  19. $counter = 1;
  20. foreach ($records as $record) {
  21. $sql = "UPDATE categories SET category_order='$counter' WHERE id='$record'";
  22. $query = $mysqli->query($sql);
  23. $counter = $counter + 1;
  24. }
  25. }
  26. if ($action == "sort_pages"){
  27. $records = $_POST['records'];
  28. $counter = 1;
  29. foreach ($records as $record) {
  30. $sql = "UPDATE pages SET page_order='$counter' WHERE id='$record'";
  31. $query = $mysqli->query($sql);
  32. $counter = $counter + 1;
  33. }
  34. }
  35.  
  36. if ($action == "sort_links"){
  37. $records = $_POST['records'];
  38. $counter = 1;
  39. foreach ($records as $record) {
  40. $sql = "UPDATE links SET link_order='$counter' WHERE id='$record'";
  41. $query = $mysqli->query($sql);
  42. $counter = $counter + 1;
  43. }
  44. }
  45. if ($case == "ajax_remove_from_list"){
  46. if (isset($_GET)) {
  47. $id = make_safe(xss_clean($_GET['id']));
  48. $delete = $mysqli->query("DELETE FROM lists_video WHERE id='$id'");
  49. if ($delete) {
  50. echo 1;
  51. } else {
  52. echo 0;
  53. }
  54. }
  55. }
  56.  
  57. if ($case == "video_details"){
  58. $id = make_safe(xss_clean($_GET['id']));
  59. ?>
  60. <div class="modal-dialog" id="media-details">
  61. <div class="modal-content">
  62. <div class="modal-header">
  63. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  64. <h4 class="modal-title">Video Details</h4>
  65. </div>
  66. <div class="modal-body">
  67. <div class="embed-responsive embed-responsive-16by9">
  68. <iframe src="http://w...content-available-to-author-only...e.com/embed/<?php echo $id; ?>"></iframe>
  69. </div>
  70. </div>
  71. <div class="modal-footer">
  72. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  73. </div>
  74. </div>
  75. </div>
  76. <?php
  77. }
  78.  
  79. if ($action == "sort_videos_list"){
  80. $records = $_POST['records'];
  81. $counter = 1;
  82. foreach ($records as $record) {
  83. $sql = "UPDATE lists_video SET video_order='$counter' WHERE id='$record'";
  84. $query = $mysqli->query($sql);
  85. $counter = $counter + 1;
  86. }
  87. }
  88. if ($action == "youtube_channel_import") {
  89.  
  90. $id = intval($_POST['id']);
  91. if (empty($id)) {
  92. header("location:login.php");
  93. }
  94. $sql = "SELECT * FROM channels WHERE id='$id' LIMIT 1";
  95. $query = $mysqli->query($sql);
  96. $row = $query->fetch_assoc();
  97. $category_id = $row['category_id'];
  98. $channel_id = $row['id'];
  99. $channel_link = $row['link'];
  100. $videos_number = $row['videos_number'];
  101. $day = date('j');
  102. $month = date('n');
  103. $year = date('Y');
  104. $u = parse_url($channel_link);
  105. if (strpos($channel_link,'/user/') != false) {
  106. $youtube_username = str_replace('/user/','',$u['path']);
  107. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  108. $apiKey = $options['api_youtube_apikey'];
  109. $link = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/channels?key='.$apiKey.'&forUsername='.$youtube_username.'&part=id'), true);
  110. $channelId = $link['items'][0]['id'];
  111. } else {
  112. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  113. $apiKey = $options['api_youtube_apikey'];
  114. $youtube_username = str_replace('/channel/','',$u['path']);
  115. $channelId = $youtube_username;
  116. }
  117. $url = $baseUrl .'channels?' .
  118. 'id=' . $channelId .
  119. '&part=contentDetails' .
  120. '&key=' . $apiKey;
  121. $json = json_decode(file_get_contents($url), true);
  122.  
  123. $playlist = $json['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
  124.  
  125. $url = $baseUrl .'playlistItems?' .
  126. 'part=snippet' .
  127. '&maxResults=' .$videos_number.
  128. '&playlistId=' . $playlist .
  129. '&key=' . $apiKey;
  130. $json = json_decode(file_get_contents($url), true);
  131. foreach(array_reverse($json['items']) as $video) {
  132. $video_id = $video['snippet']['resourceId']['videoId'];
  133. $video_title = htmlspecialchars($video['snippet']['title'],ENT_QUOTES);
  134. $video_details = htmlspecialchars($video['snippet']['description'],ENT_QUOTES);
  135. if (!empty($video['snippet']['thumbnails']['standard']['url'])) {
  136. $video_thumbnail = $video['snippet']['thumbnails']['standard']['url'];
  137. } else {
  138. $video_thumbnail = $video['snippet']['thumbnails']['high']['url'];
  139. }
  140. $video_youtube_url = 'http://w...content-available-to-author-only...e.com/watch?v='.$video_id;
  141. if (check_youtube_id($video_id) == 0) {
  142. $videt = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey), true);
  143. $video_duration = $videt['items'][0]['contentDetails']['duration'];
  144. $duration = youtube_duration($video_duration);
  145. $datetime = time();
  146. if (!empty($video_thumbnail)) {
  147. $thumb = $video_id.'.jpg';
  148. $up = file_put_contents('../upload/videos/'.$thumb,file_get_contents($video_thumbnail));
  149. } else {
  150. $thumb = '';
  151. }
  152. if (count($video['snippet']['tags']) > 0) {
  153. $tags = implode(',',$video['snippet']['tags']);
  154. } else {
  155. $tags = title_to_keywords($video['snippet']['title']);
  156. }
  157. $publish_time = youtube_date_to_unix($video['snippet']['publishedAt']);
  158. $datetime = time();
  159. $day = date('j');
  160. $month = date('n');
  161. $year = date('Y');
  162. $insert = $mysqli->query("INSERT INTO videos (user_id,youtube_id,channel_id,category_id,title,details,permalink,datetime,thumbnail,duration,tags,day,month,year,published,publish_time,tag_id,hits,deleted,votes_up,votes_down) VALUES ('$_SESSION[youtube_pro_user]','$video_id','$channel_id','$category_id','$video_title','$video_details','$video_youtube_url','$datetime','$thumb','$duration','$tags','$day','$month','$year','1','$publish_time','0','0','0','0','0')");
  163. }
  164. }
  165.  
  166.  
  167. $now = time();
  168. $mysqli->query("UPDATE channels SET latest_activity='$now' WHERE id='$id'");
  169. }
  170.  
  171.  
  172. // import single video
  173. if ($action == "import_single_youtube_video") {
  174. $id = make_safe($_POST['id']);
  175. $category = make_safe($_POST['category']);
  176. if (empty($id)) {
  177. header("location:login.php");
  178. }
  179. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  180. $apiKey = $options['api_youtube_apikey'];
  181. $url = $baseUrl .'videos?' .
  182. 'id=' .$id.
  183. '&part=snippet' .
  184. '&key=' . $apiKey;
  185. $json = json_decode(file_get_contents($url), true);
  186. if (count($json['items']) == 0) {
  187. echo 'failure';
  188. } else {
  189. $video_title = htmlspecialchars($json['items'][0]['snippet']['title'],ENT_QUOTES);
  190. $video_details = htmlspecialchars($json['items'][0]['snippet']['description'],ENT_QUOTES);
  191. if (!empty($json['items'][0]['snippet']['thumbnails']['standard']['url'])) {
  192. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['standard']['url'];
  193. } else {
  194. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['high']['url'];
  195. }
  196. $video_youtube_url = 'http://w...content-available-to-author-only...e.com/watch?v='.$id;
  197. $videt = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/videos?id='.$id.'&part=contentDetails&key='.$apiKey), true);
  198. $video_duration = $videt['items'][0]['contentDetails']['duration'];
  199. $duration = youtube_duration($video_duration);
  200. if (check_youtube_id($id) == 0) {
  201. $datetime = time();
  202. $day = date('j');
  203. $month = date('n');
  204. $year = date('Y');
  205. if (!empty($video_thumbnail)) {
  206. $thumb = 'youtube_'.$id.'.jpg';
  207. $up = file_put_contents('../upload/videos/'.$thumb,file_get_contents($video_thumbnail));
  208. } else {
  209. $thumb = '';
  210. }
  211. if (count($json['items'][0]['snippet']['tags']) > 0) {
  212. $tags = implode(',',$json['items'][0]['snippet']['tags']);
  213. } else {
  214. $tags = title_to_keywords($json['items'][0]['snippet']['title']);
  215. }
  216. $publish_time = youtube_date_to_unix($json['items'][0]['snippet']['publishedAt']);
  217. $datetime = time();
  218. $day = date('j');
  219. $month = date('n');
  220. $year = date('Y');
  221. $insert = $mysqli->query("INSERT INTO videos
  222. (youtube_id,user_id,category_id,title,details,permalink,datetime,thumbnail,duration,day,month,year,published,tags,publish_time,tag_id,channel_id,hits,deleted,votes_up,votes_down) VALUES
  223. ('$id','$_SESSION[youtube_pro_user]','$category','$video_title','$video_details','$video_youtube_url','$datetime','$thumb','$duration','$day','$month','$year','1','$tags','$publish_time','0','0','0','0','0','0')");
  224. if ($insert) {
  225. echo 'success';
  226. } else {
  227. echo 'failure';
  228. }
  229. } else {
  230. echo 'failure';
  231. }
  232. }
  233. }
  234.  
  235.  
  236.  
  237. if ($action == "import_channel_single_video") {
  238. if (isset($_POST)) {
  239. $category = make_safe(xss_clean(intval($_POST['category'])));
  240. $channel = make_safe(xss_clean(intval($_POST['channel'])));
  241. $id = make_safe(xss_clean($_POST['id']));
  242. $datetime = time();
  243. $day = date('j');
  244. $month = date('n');
  245. $year = date('Y');
  246. if (empty($id)) {
  247. echo 'failure';
  248. } elseif (check_youtube_id($id) > 0) {
  249. echo 'failure';
  250. } else {
  251. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  252. $apiKey = $options['api_youtube_apikey'];
  253. $url = $baseUrl.'videos?'.
  254. 'id='.$id.
  255. '&part=snippet'.
  256. '&key='.$apiKey;
  257. $json = json_decode(file_get_contents($url), true);
  258. if (count($json['items']) == 0) {
  259. echo 'failure';
  260. } else {
  261. $video_title = htmlspecialchars($json['items'][0]['snippet']['title'],ENT_QUOTES);
  262. $video_details = htmlspecialchars($json['items'][0]['snippet']['description'],ENT_QUOTES);
  263. if (!empty($json['items'][0]['snippet']['thumbnails']['standard']['url'])) {
  264. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['standard']['url'];
  265. } else {
  266. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['high']['url'];
  267. }
  268. $video_youtube_url = 'http://w...content-available-to-author-only...e.com/watch?v='.$id;
  269. $videt = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/videos?id='.$id.'&part=contentDetails&key='.$apiKey), true);
  270. $video_duration = $videt['items'][0]['contentDetails']['duration'];
  271. preg_match_all('!\d+!', $video_duration, $matches);
  272. $m = $matches[0][0];
  273. $s = $matches[0][1];
  274. $duration = ($m*60)+$s;
  275. if (!empty($video_thumbnail)) {
  276. $thumb = 'youtube_'.$id.'.jpg';
  277. $up = file_put_contents('../upload/videos/'.$thumb,file_get_contents($video_thumbnail));
  278. } else {
  279. $thumb = '';
  280. }
  281. if (count($json['items'][0]['snippet']['tags']) > 0) {
  282. $tags = implode(',',$json['items'][0]['snippet']['tags']);
  283. } else {
  284. $tags = title_to_keywords($json['items'][0]['snippet']['title']);
  285. }
  286. $publish_time = youtube_date_to_unix($json['items'][0]['snippet']['publishedAt']);
  287. $datetime = time();
  288. $day = date('j');
  289. $month = date('n');
  290. $year = date('Y');
  291. $insert = $mysqli->query("INSERT INTO videos (youtube_id,user_id,category_id,channel_id,title,details,permalink,datetime,thumbnail,duration,day,month,year,published,tags,publish_time,tag_id,hits,deleted,votes_up,votes_down) VALUES ('$id','$_SESSION[youtube_pro_user]','$category','$channel','$video_title','$video_details','$video_youtube_url','$datetime','$thumb','$duration','$day','$month','$year','1','$tags','$publish_time','0','0','0','0','0')");
  292. if ($insert) {
  293. echo 1;
  294. } else {
  295. echo 'failure';
  296. }
  297. }
  298. }
  299. }
  300. }
  301.  
  302. if ($case == 'channel_details') {
  303. $id = make_safe($_GET['id']);
  304. if (!empty($id)) {
  305. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  306. $apiKey = $options['api_youtube_apikey'];
  307. $url = $baseUrl .'channels?' .
  308. 'id=' . $_GET['id'] .
  309. '&part=snippet' .
  310. '&key=' . $apiKey;
  311. $json = json_decode(file_get_contents($url), true);
  312. $urla = $baseUrl .'channels?' .
  313. 'id=' . $_GET['id'] .
  314. '&part=statistics' .
  315. '&key=' . $apiKey;
  316. $jsona = json_decode(file_get_contents($urla), true);
  317. ?>
  318. <div class="modal-dialog" id="channel-details">
  319. <div class="modal-content">
  320. <div class="modal-header">
  321. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  322. <h4 class="modal-title">Channel Details</h4>
  323. </div>
  324. <div class="modal-body">
  325. <table class="table">
  326. <thead>
  327. <tr>
  328. <th>Field</th>
  329. <th>Value</th>
  330. </tr>
  331. </thead>
  332. <tbody>
  333. <tr>
  334. <td>Channel Name</td>
  335. <td><?php echo $json['items'][0]['snippet']['title']; ?></td>
  336. </tr>
  337. <tr>
  338. <td>Channel Description</td>
  339. <td><?php echo $json['items'][0]['snippet']['description']; ?></td>
  340. </tr>
  341. <tr>
  342. <td>Videos Number</td>
  343. <td><?php echo $jsona['items'][0]['statistics']['videoCount']; ?></td>
  344. </tr>
  345. <tr>
  346. <td>Subscribers Number</td>
  347. <td><?php echo $jsona['items'][0]['statistics']['subscriberCount']; ?></td>
  348. </tr>
  349. <tr>
  350. <td>Views Number</td>
  351. <td><?php echo $jsona['items'][0]['statistics']['viewCount']; ?></td>
  352. </tr>
  353. </tbody>
  354. </table>
  355. </div>
  356. <div class="modal-footer">
  357. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  358. </div>
  359. </div>
  360. </div>
  361. <?php
  362. }
  363. }
  364.  
  365.  
  366. if ($action == 'import_single_channel') {
  367. $id = make_safe($_POST['id']);
  368. $category = make_safe($_POST['category']);
  369. if (!empty($id)) {
  370. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  371. $apiKey = $options['api_youtube_apikey'];
  372. $url = $baseUrl .'channels?' .
  373. 'id=' . $id.
  374. '&part=snippet' .
  375. '&key=' . $apiKey;
  376. $json = json_decode(file_get_contents($url), true);
  377. if (count($json['items']) != 0) {
  378. if (check_youtube_channel_id($json['items'][0]['id']) == 0) {
  379. $datetime = time();
  380. $title = $json['items'][0]['snippet']['title'];
  381. $link = 'http://y...content-available-to-author-only...e.com/channel/'.$json['items'][0]['id'];
  382. $sql = "INSERT INTO channels (title,link,category_id,videos_number,add_time,latest_activity,auto_update,auto_update_period,youtube_channel_id) VALUES ('$title','$link','$category','30','$datetime','0','0','0','$id')";
  383. $query = $mysqli->query($sql);
  384. if ($query) {
  385. echo 'success';
  386. } else {
  387. echo 'failure';
  388. }
  389. } else {
  390. echo 'failure';
  391. }
  392. } else {
  393. echo 'failure';
  394. }
  395. } else {
  396. echo 'failure';
  397. }
  398. }
  399.  
  400.  
  401. if ($action == "import_multiple_videos") {
  402.  
  403. $category = intval($_POST['category']);
  404. $ids = explode(',',$_POST['myCheckboxes']);
  405. for ( $i=0; $i < count($ids); $i++)
  406. {
  407. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  408. $apiKey = $options['api_youtube_apikey'];
  409. $url = $baseUrl.'videos?'.
  410. 'id='.$ids[$i].
  411. '&part=snippet'.
  412. '&key='.$apiKey;
  413. $json = json_decode(file_get_contents($url), true);
  414. if (count($json['items']) != 0) {
  415. $video_title = htmlspecialchars($json['items'][0]['snippet']['title'],ENT_QUOTES);
  416. $video_details = htmlspecialchars($json['items'][0]['snippet']['description'],ENT_QUOTES);
  417. if (!empty($json['items'][0]['snippet']['thumbnails']['standard']['url'])) {
  418. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['standard']['url'];
  419. } else {
  420. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['high']['url'];
  421. }
  422. $video_youtube_url = 'http://w...content-available-to-author-only...e.com/watch?v='.$ids[$i];
  423. $videt = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/videos?id='.$ids[$i].'&part=contentDetails&key='.$apiKey), true);
  424. $video_duration = $videt['items'][0]['contentDetails']['duration'];
  425. preg_match_all('!\d+!', $video_duration, $matches);
  426. $m = $matches[0][0];
  427. $s = $matches[0][1];
  428. $duration = ($m*60)+$s;
  429. if (!empty($video_thumbnail)) {
  430. $thumb = 'youtube_'.$ids[$i].'.jpg';
  431. $up = file_put_contents('../upload/videos/'.$thumb,file_get_contents($video_thumbnail));
  432. } else {
  433. $thumb = '';
  434. }
  435. if (count($json['items'][0]['snippet']['tags']) > 0) {
  436. $tags = implode(',',$json['items'][0]['snippet']['tags']);
  437. } else {
  438. $tags = title_to_keywords($json['items'][0]['snippet']['title']);
  439. }
  440. $publish_time = youtube_date_to_unix($json['items'][0]['snippet']['publishedAt']);
  441. $datetime = time();
  442. $day = date('j');
  443. $month = date('n');
  444. $year = date('Y');
  445. $insert = $mysqli->query("INSERT INTO videos (youtube_id,user_id,category_id,title,details,permalink,datetime,thumbnail,duration,day,month,year,published,tags,publish_time,channel_id,tag_id,hits,deleted,votes_up,votes_down) VALUES ('$ids[$i]','$_SESSION[youtube_pro_user]','$category','$video_title','$video_details','$video_youtube_url','$datetime','$thumb','$duration','$day','$month','$year','1','$tags','$publish_time','0','0','0','0','0','0')");
  446. }
  447. }
  448.  
  449.  
  450. }
  451.  
  452.  
  453. if ($action == "import_multiple_videos_from_channel") {
  454.  
  455. $category = intval($_POST['category']);
  456. $channel_id = intval($_POST['channel_id']);
  457. $ids = explode(',',$_POST['myCheckboxes']);
  458. for ( $i=0; $i < count($ids); $i++)
  459. {
  460. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  461. $apiKey = $options['api_youtube_apikey'];
  462. $url = $baseUrl.'videos?'.
  463. 'id='.$ids[$i].
  464. '&part=snippet'.
  465. '&key='.$apiKey;
  466. $json = json_decode(file_get_contents($url), true);
  467. if (count($json['items']) != 0) {
  468. $video_title = htmlspecialchars($json['items'][0]['snippet']['title'],ENT_QUOTES);
  469. $video_details = htmlspecialchars($json['items'][0]['snippet']['description'],ENT_QUOTES);
  470. if (!empty($json['items'][0]['snippet']['thumbnails']['standard']['url'])) {
  471. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['standard']['url'];
  472. } else {
  473. $video_thumbnail = $json['items'][0]['snippet']['thumbnails']['high']['url'];
  474. }
  475. $video_youtube_url = 'http://w...content-available-to-author-only...e.com/watch?v='.$ids[$i];
  476. $videt = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/videos?id='.$ids[$i].'&part=contentDetails&key='.$apiKey), true);
  477. $video_duration = $videt['items'][0]['contentDetails']['duration'];
  478. preg_match_all('!\d+!', $video_duration, $matches);
  479. $m = $matches[0][0];
  480. $s = $matches[0][1];
  481. $duration = ($m*60)+$s;
  482. if (!empty($video_thumbnail)) {
  483. $thumb = 'youtube_'.$ids[$i].'.jpg';
  484. $up = file_put_contents('../upload/videos/'.$thumb,file_get_contents($video_thumbnail));
  485. } else {
  486. $thumb = '';
  487. }
  488. if (count($json['items'][0]['snippet']['tags']) > 0) {
  489. $tags = implode(',',$json['items'][0]['snippet']['tags']);
  490. } else {
  491. $tags = title_to_keywords($json['items'][0]['snippet']['title']);
  492. }
  493. $publish_time = youtube_date_to_unix($json['items'][0]['snippet']['publishedAt']);
  494. $datetime = time();
  495. $day = date('j');
  496. $month = date('n');
  497. $year = date('Y');
  498. $insert = $mysqli->query("INSERT INTO videos (youtube_id,user_id,category_id,channel_id,title,details,permalink,datetime,thumbnail,duration,day,month,year,published,tags,publish_time,tag_id,hits,deleted,votes_up,votes_down) VALUES ('$ids[$i]','$_SESSION[youtube_pro_user]','$category','$channel_id','$video_title','$video_details','$video_youtube_url','$datetime','$thumb','$duration','$day','$month','$year','1','$tags','$publish_time','0','0','0','0','0')");
  499. }
  500. }
  501.  
  502.  
  503. }
  504.  
  505. if ($action == "youtube_tag_import") {
  506.  
  507. $id = intval($_POST['id']);
  508. $tag = $general->tag($id);
  509. if ($tag != 0) {
  510. $tag_title = str_replace(' ','+',$tag['title']);
  511. $tag_id = $tag['id'];
  512. $category_id = $tag['category_id'];
  513. $max_results = $tag['videos_number'];
  514. $youtube_category = $tag['youtube_category'];
  515. $baseUrl = 'https://w...content-available-to-author-only...s.com/youtube/v3/';
  516. $apiKey = $options['api_youtube_apikey'];
  517. $url = $baseUrl ."search?q=$tag_title&maxResults=$max_results&order=date&part=snippet&type=video";
  518. if ($youtube_category != 0) {
  519. $url .= "&videoCategoryId=$youtube_category";
  520. }
  521. $url .= "&key=$apiKey";
  522. $json = json_decode(file_get_contents($url), true);
  523. foreach(array_reverse($json['items']) as $video) {
  524. $video_id = $video['id']['videoId'];
  525. $video_title = htmlspecialchars($video['snippet']['title'],ENT_QUOTES);
  526. $video_details = htmlspecialchars($video['snippet']['description'],ENT_QUOTES);
  527. if (!empty($video['snippet']['thumbnails']['standard']['url'])) {
  528. $video_thumbnail = $video['snippet']['thumbnails']['standard']['url'];
  529. } else {
  530. $video_thumbnail = $video['snippet']['thumbnails']['high']['url'];
  531. }
  532. $video_youtube_url = 'http://w...content-available-to-author-only...e.com/watch?v='.$video_id;
  533. if (check_youtube_id($video_id) == 0) {
  534. $videt = json_decode(file_get_contents('https://w...content-available-to-author-only...s.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey), true);
  535. $video_duration = $videt['items'][0]['contentDetails']['duration'];
  536. $duration = youtube_duration($video_duration);
  537. $datetime = time();
  538. if (!empty($video_thumbnail)) {
  539. $thumb = $video_id.'.jpg';
  540. $up = file_put_contents('../upload/videos/'.$thumb,file_get_contents($video_thumbnail));
  541. } else {
  542. $thumb = '';
  543. }
  544. if (count($video['snippet']['tags']) > 0) {
  545. $tags = implode(',',$video['snippet']['tags']);
  546. } else {
  547. $tags = title_to_keywords($video['snippet']['title']);
  548. }
  549. $publish_time = youtube_date_to_unix($video['snippet']['publishedAt']);
  550. $datetime = time();
  551. $day = date('j');
  552. $month = date('n');
  553. $year = date('Y');
  554. $insert = $mysqli->query("INSERT INTO videos (user_id,youtube_id,tag_id,category_id,title,details,permalink,datetime,thumbnail,duration,tags,day,month,year,published,publish_time,channel_id,hits,deleted,votes_up,votes_down) VALUES ('$_SESSION[youtube_pro_user]','$video_id','$tag_id','$category_id','$video_title','$video_details','$video_youtube_url','$datetime','$thumb','$duration','$tags','$day','$month','$year','1','$publish_time','0','0','0','0','0')");
  555. }
  556. }
  557. $now = time();
  558. $mysqli->query("UPDATE tags SET latest_activity='$now' WHERE id='$id'");
  559. }
  560.  
  561. }
Success #stdin #stdout 0.01s 82560KB
stdin
Standard input is empty
stdout
Standard output is empty