|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/parasoffline.edukrypt.in/application/modules/admin/controllers/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require(APPPATH . "third_party/vendor/autoload.php");
class Vodserver extends Admin_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('form_builder');
$this->load->model(['vod_model', 'lecture_model', 'Main_model']);
if (empty($this->session->userdata('user_id'))) {
redirect('admin/panel/logout');
}
}
public function list()
{
$admin_id = $this->session->userdata('user_id');
$this->mViewData['p_type'] = "list";
$this->mViewData['message'] = $this->session->flashdata('upload_success');
$this->mTitle .= ' VOD Server List';
$this->render('vodserver/list');
}
// Bunny Server
public function sync_vod_server()
{
$this->db->truncate('collection_album');
$admin_id = $this->session->userdata('user_id');
$PER_PAGE = 20;
$client = new \GuzzleHttp\Client();
$URL = "http://video.bunnycdn.com/library/" . BUNNY_LIBRARY_ID . "/videos?page=1&itemsPerPage=20&orderBy=date";
$response = $client->request('GET', $URL, [
'headers' => [
'Accept' => 'application/json',
'AccessKey' => BUNNY_API_KEY,
],
]);
$JsonResp = json_decode($response->getBody());
if ($JsonResp->totalItems > $PER_PAGE) {
$PAGES = ceil($JsonResp->totalItems / $PER_PAGE);
for ($i = 1; $i <= $PAGES; $i++) {
// print_r($JsonResp);
$_URL = "http://video.bunnycdn.com/library/" . BUNNY_LIBRARY_ID . "/videos?page=" . $i . "&itemsPerPage=" . $PER_PAGE . "&orderBy=date";
$_response = $client->request('GET', $_URL, [
'headers' => [
'Accept' => 'application/json',
'AccessKey' => BUNNY_API_KEY,
],
]);
$_JsonResp = json_decode($_response->getBody());
$videoData = array();
foreach ($_JsonResp->items as $item) {
$videoData[] = array(
'video_id' => $item->guid,
'library_id' => $item->videoLibraryId,
'name' => $item->title,
'duration' => $item->length,
'admin_id' => $admin_id,
'created' => date('Y-m-d H:i:s')
);
}
$this->db->insert_batch('collection_album', $videoData);
}
} else {
$_JsonResp = json_decode($response->getBody());
$videoData = array();
foreach ($_JsonResp->items as $item) {
$videoData[] = array(
'video_id' => $item->guid,
'library_id' => $item->videoLibraryId,
'name' => $item->title,
'duration' => $item->length,
'admin_id' => $admin_id,
'created' => date('Y-m-d H:i:s')
);
}
$this->db->insert_batch('collection_album', $videoData);
}
}
public function posts()
{
$columns = array(
0 => 'video_id',
1 => 'library_id',
2 => 'name',
3 => 'duration',
4 => 'created'
);
if ($this->session->userdata('user_id') == 1) {
$admin_id = null;
} else {
$admin_id = $this->session->userdata('user_id');
}
$limit = $this->input->post('length');
$start = $this->input->post('start');
$order = $columns[$this->input->post('order')[0]['column']];
$dir = $this->input->post('order')[0]['dir'];
$totalData = $this->vod_model->check_permission_posts_count($admin_id);
$totalFiltered = $totalData;
if (empty($this->input->post('search')['value'])) {
$posts = $this->vod_model->check_permission_posts($limit, $start, $order, $dir, $admin_id);
} else {
$search = $this->input->post('search')['value'];
$posts = $this->vod_model->check_permission_posts_search($limit, $start, $search, $order, $dir, $admin_id);
$totalFiltered = $this->vod_model->check_permission_posts_search_count($search, $admin_id);
}
$data = array();
if (!empty($posts)) {
$i = 1;
foreach ($posts as $post) {
$nestedData['id'] = '<input type="checkbox" class="_check_in" value="' . $post->video_id . '">';
$nestedData['video_id'] = '<span style="font-size: 12px;">' . $post->video_id . '</span>';
$nestedData['library_id'] = '<span style="font-size: 12px;">' . $post->library_id . '</span>';
$nestedData['name'] = '<span style="font-size: 12px;">' . $post->name . '</span>';
$nestedData['duration'] = '<span style="font-size: 12px;">' . $post->duration . '</span>';
$nestedData['created'] = '<span style="font-size: 12px;">' . date('m F Y', strtotime($post->created)) . '</span>';
$nestedData['actions'] = "<a onclick='return confirm(\"Are you sure you want to delete?\")' class='btn btn-danger btn-sm' href='" . base_url('admin/vodserver/delete/' . $post->video_id) . "' title='Delete'>Trash</a>";
$data[] = $nestedData;
}
}
$json_data = array(
"draw" => intval($this->input->post('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
// "data" => $this->db->last_query()
);
echo json_encode($json_data);
}
// Delete Videos
public function delete($video_id = NULL)
{
if (!empty($video_id)) {
$this->db->where('video_id', $video_id);
$queryData = $this->db->get('collection_album', 1);
if ($queryData->num_rows() > 0) {
$this->delete_server_3($video_id);
$this->session->set_flashdata('message', '<div class="alert alert-success">Video deleted successfully from server!</div>');
redirect('admin/vodserver/list');
}
$this->session->set_flashdata('message', '<div class="alert alert-danger">No video found on server!</div>');
redirect('admin/vodserver/list');
}
$this->session->set_flashdata('message', '<div class="alert alert-danger">No video found on server!</div>');
redirect('admin/vodserver/list');
}
public function delete_all()
{
$videos = $_POST['video_ids'];
if (!empty($videos)) {
foreach ($videos as $value) {
$this->delete_server_3($value);
}
return true;
}
return true;
}
// Bunny Server
public function delete_server_3($embed)
{
$client = new \GuzzleHttp\Client();
try {
$URL = "https://video.bunnycdn.com/library/" . BUNNY_LIBRARY_ID . "/videos" . "/" . $embed;
$response = $client->request('DELETE', $URL, [
'headers' => [
'Accept' => 'application/json',
'AccessKey' => BUNNY_API_KEY,
],
]);
$JsonResp = $response->getBody();
} catch (\GuzzleHttp\Exception\RequestException $exception) {
$this->session->set_flashdata('message', '<div class="alert alert-danger">No video found on server or already deleted!</div>');
redirect('admin/vodserver/list');
}
$this->db->where('video_id', $embed);
$this->db->delete('collection_album');
}
public function upload()
{
$admin_id = $this->session->userdata('user_id');
$this->mViewData['p_type'] = "list";
$this->mViewData['message'] = $this->session->flashdata('upload_success');
$this->mTitle .= ' VOD Server Upload';
$this->render('vodserver/upload');
}
// Create Video Bunny ID
public function get_video_id_bunny()
{
$file_info = $_POST['file'];
// print_r($file_info);
// exit;
$client = new \GuzzleHttp\Client();
$URL = "http://video.bunnycdn.com/library/" . BUNNY_LIBRARY_ID . "/videos";
$body = array(
"title" => $file_info,
"collectionId" => BUNNY_COLLECTION_ID
);
$response = $client->request('POST', $URL, [
'body' => json_encode($body),
'headers' => [
'Accept' => 'application/json',
'AccessKey' => BUNNY_API_KEY,
'Content-Type' => 'application/*+json',
],
]);
$arrayData = json_decode($response->getBody());
$expiration_time = strtotime("+1 days");
$sha256 = hash('sha256', BUNNY_LIBRARY_ID . BUNNY_API_KEY . $expiration_time . $arrayData->guid);
$header = array(
'AuthorizationSignature' => $sha256,
'AuthorizationExpire' => $expiration_time,
'VideoId' => $arrayData->guid,
'LibraryId' => $arrayData->videoLibraryId
);
echo json_encode($header);
}
}