Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace App\Http\Controllers; use App\Common; use App\Models\BackgroundCategory; ..
Decoded Output download
<?php
namespace App\Http\Controllers; use App\Common; use App\Models\BackgroundCategory; use App\Models\Constant\PermissionConstant; use App\Models\DocumentEmbed; use App\Models\Lesson; use App\Models\LibraryFile; use App\Models\LibraryFileUserPermission; use App\Models\Slide; use App\Models\SlideAnimation; use App\Models\SlideAudio; use App\Models\SlideJson; use App\Models\SlideResource; use App\Models\SlideVideo; use App\Models\Teacher; use App\Models\TemplateCategory; use App\Models\TemplateContent; use App\Models\TemplateJson; use App\Models\Test\Category; use App\PermissionManager; use App\Util\EMp3; use FFMpeg\FFMpeg; use Illuminate\Http\Request; use Illuminate\Support\Facades\File; class SlideController extends ControllerTeacher { protected $image_destination; protected $upload_destination; public function __construct() { $this->middleware("auth"); $this->upload_destination = config("env.upload_destination"); $this->image_destination = config("env.image_destination"); } public function indexOld($lesson_id) { $lesson = Lesson::find($lesson_id); $slide_mgr = new Slide(); $select_arr = array("Id", "Index", "Name", "FileUrl"); $slideList = $slide_mgr->getListSlideBySection($lesson->Id, $lesson->ContentVersion, $select_arr); $slide_template = TemplateCategory::GetAll(); $slide_background = BackgroundCategory::GetAll(); return view("content.slide.make", compact("slideList", "slide_template", "slide_background", "lesson")); } public function index($lesson_id) { $this->checkPermission($lesson_id); $lesson = Lesson::find($lesson_id); $slide_mgr = new Slide(); $select_arr = array("Id", "Index", "Name", "FileUrl"); $slideList = $slide_mgr->getListSlideBySection($lesson->Id, $lesson->ContentVersion, $select_arr); $slide_template = TemplateCategory::GetAll(); $slide_background = BackgroundCategory::GetAll(); return view("beta.content.make_slide.make", compact("slideList", "slide_template", "slide_background", "lesson")); } public function indexNew($lesson_id) { $this->checkPermission($lesson_id); $lesson = Lesson::find($lesson_id); $slide_mgr = new Slide(); $select_arr = array("Id", "Index", "Name", "FileUrl"); $slideList = $slide_mgr->getListSlideBySection($lesson->Id, $lesson->ContentVersion, $select_arr); $slide_template = TemplateCategory::GetAll(); $slide_background = BackgroundCategory::GetAll(); return view("beta.content.make_slide._new.make", compact("slideList", "slide_template", "slide_background", "lesson")); } function checkPermission($lesson_id, $slide_id = 0) { if (PermissionManager::IsAdmin()) { return true; } if ($lesson_id == 0) { $slide = Slide::find($slide_id); if (!isset($slide)) { abort(403); } $lesson_id = $slide->Section_Id; } $libFile = LibraryFile::where("Type", LibraryFile::TYPE_SLIDE)->where("OrganizationId", Teacher::GetOrganizationId())->where("ContentId", $lesson_id)->where("DeletedFlag", 0)->first(); if (PermissionManager::IsOrganizationAdmin()) { if ($libFile->OrganizationId == Teacher::GetOrganizationId()) { return true; } } if ($libFile->OwnerId == 0 || $libFile->OwnerId == Teacher::Current()->Id) { return true; } $ids = array($libFile->Id, $libFile->P1, $libFile->P2, $libFile->P3, $libFile->P4); $ids = array_filter($ids, function ($item) { return $item > 0; }); $filePermission = LibraryFileUserPermission::whereIn("FileId", $ids)->where("UserId", Teacher::Current()->Id)->where("Action", LibraryFileUserPermission::ACTION_EDIT)->first(); if (isset($filePermission)) { return true; } abort(403); } public function revertSlideToVersion($lesson_id, $version) { if (!PermissionManager::IsAdmin()) { abort(404); } $lesson = Lesson::find($lesson_id); $currentSlides = $lesson->Slides(); $lastSlides = $lesson->SlidesWithVersion($version); $image_destination = config("env.image_destination"); foreach ($currentSlides as $currentSlide) { foreach ($lastSlides as $lastSlide) { if ($lastSlide->Index == $currentSlide->Index) { if (isset($lastSlide->FileJsonUrl)) { $json_save = file_get_contents($image_destination . $lastSlide->FileJsonUrl); SlideJson::saveJson($currentSlide->Id, $json_save); } } } } echo "revert success"; die; } public function revertAllSlide() { if (!PermissionManager::IsAdmin()) { abort(404); } $lessons = Lesson::where("DeletedFlag", 0)->where("RevertStatus", 0)->take(10)->get(); foreach ($lessons as $lesson) { $lastZip = $lesson->LastSlideZip(); if (isset($lastZip)) { $currentSlides = $lesson->Slides(); $lastSlides = $lesson->SlidesWithVersion($lastZip->Version); $image_destination = config("env.image_destination"); foreach ($currentSlides as $currentSlide) { foreach ($lastSlides as $lastSlide) { if ($lastSlide->Index == $currentSlide->Index) { if (isset($lastSlide->FileJsonUrl)) { $json_save = file_get_contents($image_destination . $lastSlide->FileJsonUrl); SlideJson::saveJson($currentSlide->Id, $json_save); } } } } } $lesson->RevertStatus = 1; $lesson->save(); } echo "revert success"; die; } public function createSlideAudio(Request $request) { try { $this->checkPermission(0, $request->get("slide_id")); $organizationId = Teacher::GetOrganizationId(); if (!File::isDirectory($this->upload_destination . "/" . $organizationId)) { File::makeDirectory($this->upload_destination . "/" . $organizationId); } $data = array(); $audio = $request->file("slide_audio"); $start_time = $request->get("start_time"); $end_time = $request->get("end_time"); $file_etc = $audio->getClientOriginalExtension(); $time = uniqid() . Common::generateRandomString(7); $data["Slide_Id"] = $request->get("slide_id"); $data["Top"] = 20; $data["Right"] = 30; $data["Left"] = 20; $data["Bottom"] = 30; $data["Size"] = round($audio->getSize() / 1024); Common::IncreaseStorage($organizationId, $data["Size"]); $audio_url = $organizationId . "/" . "{$time}.mp3"; if (substr(php_uname(), 0, 7) == "Windows") { $ffmpeg = FFMpeg::create(array("ffmpeg.binaries" => config("env.ffmpeg_path") . "ffmpeg.exe", "ffprobe.binaries" => config("env.ffmpeg_path") . "ffprobe.exe", "timeout" => 3600, "ffmpeg.threads" => 12)); } else { $ffmpeg = FFMpeg::create(array("ffmpeg.binaries" => config("env.ffmpeg_path") . "ffmpeg", "ffprobe.binaries" => config("env.ffmpeg_path") . "ffprobe", "timeout" => 3600, "ffmpeg.threads" => 12)); } $audio_ff = $ffmpeg->open($audio->getRealPath()); $duration = $ffmpeg->getFFProbe()->format($audio->getRealPath())->get("duration"); $format = new EMp3(); $audio_ff->save($format, config("env.upload_destination") . "/{$audio_url}"); $data["Url"] = $audio_url; $audio = SlideAudio::create($data); $result = array("Audio_Id" => $audio->Id, "Url" => $audio->Url, "Duration" => $duration, "Size" => $data["Size"]); return response()->json($result); } catch (\Exception $e) { return response()->json(array("Internal server error")); } } public function createSlideVideo(Request $request) { try { $this->checkPermission(0, $request->get("slide_id")); $organizationId = Teacher::GetOrganizationId(); if (!File::isDirectory($this->upload_destination . "/" . $organizationId)) { File::makeDirectory($this->upload_destination . "/" . $organizationId); } $video = $request->file("slide_video"); $file_etc = $video->getClientOriginalExtension(); $time = uniqid() . Common::generateRandomString(7); $slide_id = $request->get("slide_id"); $data = array(); $data["Slide_Id"] = $slide_id; $data["Top"] = 20; $data["Right"] = 40; $data["Left"] = 20; $data["Bottom"] = 40; $data["Size"] = round($video->getSize() / 1024); Common::IncreaseStorage($organizationId, $data["Size"]); $data["Url"] = $organizationId . "/" . "{$time}.{$file_etc}"; $video->move($this->upload_destination . "/" . $organizationId, "{$time}.{$file_etc}"); $audio = SlideVideo::create($data); $data["Video_Id"] = $audio->Id; return response()->json($data); } catch (\Exception $e) { return response()->json(''); } } public function updateSlideAudio(Request $request) { $audio_id = $request->get("audio_id"); $top = $request->get("top"); $left = $request->get("left"); $right = $request->get("right"); $bottom = $request->get("bottom"); $audio = SlideAudio::find($audio_id); if (isset($audio)) { $audio->Top = $top; $audio->Right = $right; $audio->Left = $left; $audio->Bottom = $bottom; $audio->update(); } return response()->json("update ok"); } public function updateSlideVideo(Request $request) { $video_id = $request->get("video_id"); $top = $request->get("top"); $left = $request->get("left"); $right = $request->get("right"); $bottom = $request->get("bottom"); $video = SlideVideo::find($video_id); if (isset($video)) { $video->Top = $top; $video->Right = $right; $video->Left = $left; $video->Bottom = $bottom; $video->save(); } return response()->json("update ok"); } public function deleteSlideAudio(Request $request) { $audio_id = $request->get("audio_id"); $audio = SlideAudio::find($audio_id); Common::DecreaseStorage(Teacher::GetOrganizationId(), $audio->Size); $audio->delete(); return response()->json("delete ok"); } public function deleteSlideVideo(Request $request) { $video_id = $request->get("video_id"); $video = SlideVideo::find($video_id); Common::DecreaseStorage(Teacher::GetOrganizationId(), $video->Size); $video->delete(); return response()->json("delete ok"); } public function getJsonTemplate(Request $request) { $template_id = $request->get("templateId"); $template = TemplateContent::find($template_id); if (isset($template)) { $contentJson = TemplateJson::getContentJson($template_id); $json_str = $contentJson != '' ? $contentJson : Common::SlideDefault(); return response()->json(array("templateJson" => $json_str)); } return response()->json(array("templateJson" => Common::SlideDefault())); } public function sbUploadAudio(Request $request) { try { $this->checkPermission(0, $request->get("slide_id")); $data = array(); $file_name = $request->get("file_name"); $data["Slide_Id"] = $request->get("slide_id"); $data["Top"] = 20; $data["Right"] = 30; $data["Left"] = 20; $data["Bottom"] = 30; $data["Url"] = $file_name; $audio = SlideAudio::create($data); $result = array("status" => true, "Audio_Id" => $audio->Id, "Url" => $audio->Url); return response()->json($result); } catch (\Exception $e) { return response()->json(array("status" => false, "message" => "Internal server error")); } } public function sbUploadVideo(Request $request) { try { $this->checkPermission(0, $request->get("slide_id")); $data = array(); $file_name = $request->get("file_name"); $filePath = config("env.upload_destination") . "/" . $file_name; $slide_id = $request->get("slide_id"); $data["Slide_Id"] = $slide_id; $data["Top"] = 20; $data["Right"] = 40; $data["Left"] = 20; $data["Bottom"] = 40; $data["Url"] = $file_name; $audio = SlideVideo::create($data); $data["Video_Id"] = $audio->Id; $data["status"] = true; return response()->json($data); } catch (\Exception $e) { return response()->json(array("status" => false, "message" => "Internal server error")); } } public function createSlideResource(Request $request) { try { $data = array(); $resource = $request->file("resource"); $data["Name"] = $request->get("name"); $data["Type"] = SlideResource::RESOURCE_AUDIO; $data["Size"] = round($resource->getSize() / 1024); $data["TeacherId"] = Teacher::GetTeacherId(); $organizationId = Teacher::GetOrganizationId(); Common::IncreaseStorage($organizationId, $data["Size"]); $time = uniqid() . Common::generateRandomString(7); $audio_url = "{$time}.mp3"; if (substr(php_uname(), 0, 7) == "Windows") { $ffmpeg = FFMpeg::create(array("ffmpeg.binaries" => config("env.ffmpeg_path") . "ffmpeg.exe", "ffprobe.binaries" => config("env.ffmpeg_path") . "ffprobe.exe", "timeout" => 3600, "ffmpeg.threads" => 12)); } else { $ffmpeg = FFMpeg::create(array("ffmpeg.binaries" => config("env.ffmpeg_path") . "ffmpeg", "ffprobe.binaries" => config("env.ffmpeg_path") . "ffprobe", "timeout" => 3600, "ffmpeg.threads" => 12)); } $audio_ff = $ffmpeg->open($resource->getRealPath()); $format = new EMp3(); $file_path = public_path() . "/resource/" . $organizationId; if (!File::isDirectory(public_path() . "/resource")) { File::makeDirectory(public_path() . "/resource"); } if (!File::isDirectory($file_path)) { File::makeDirectory($file_path); } $audio_ff->save($format, $file_path . "/{$audio_url}"); $data["FileUrl"] = "/resource/{$organizationId}/{$audio_url}"; SlideResource::create($data); $result = array("status" => true); return response()->json($result); } catch (\Exception $e) { return response()->json(array("Internal server error")); } } public function getAllResource() { return response()->json(SlideResource::GetAll()->toArray()); } public function deleteResource(Request $request) { $resourceId = $request->get("resource_id"); $resource = SlideResource::find($resourceId); if (isset($resourceId)) { $resource->DeletedFlag = 1; $resource->save(); } return response()->json(array("status", true)); } public function saveToMyTemplate(Request $request) { try { $json_save = $request->get("json_save"); $mgr = new TemplateContent(); $slide = array(); $slide["Index"] = 0; $slide["CategoryId"] = 0; $slide["ContentJson"] = ''; $slide["Type"] = TemplateContent::TEACHER; $slide["OwnerId"] = Teacher::GetTeacherId(); $thumb = $request->get("img_thumb"); $image_destination = config("env.image_destination"); if (!File::isDirectory($image_destination . "/TemplateThumb")) { File::makeDirectory($image_destination . "/TemplateThumb"); } $img = str_replace("data:image/webp;base64,", '', $thumb); $img = str_replace(" ", "+", $img); $data_img = base64_decode($img); $file_path = "/TemplateThumb/" . config("env.image_prefix") . "_" . uniqid() . Common::generateRandomString(7) . ".webp"; File::put($this->image_destination . $file_path, $data_img); $slide["Thumbnail"] = $file_path; $slideObject = $mgr->create($slide); TemplateJson::saveJson($slideObject->Id, $json_save); $result = array("status" => true); return response()->json($result); } catch (\Exception $e) { return response()->json(array("Internal server error")); } } public function saveToOrganizationTemplate(Request $request) { try { $json_save = $request->get("json_save"); $mgr = new TemplateContent(); $slide = array(); $slide["Index"] = 0; $slide["CategoryId"] = 0; $slide["ContentJson"] = ''; $slide["Type"] = TemplateContent::ORGANIZATION; $slide["OwnerId"] = Teacher::GetOrganizationId(); $thumb = $request->get("img_thumb"); $image_destination = config("env.image_destination"); if (!File::isDirectory($image_destination . "/TemplateThumb")) { File::makeDirectory($image_destination . "/TemplateThumb"); } $img = str_replace("data:image/webp;base64,", '', $thumb); $img = str_replace(" ", "+", $img); $data_img = base64_decode($img); $file_path = "/TemplateThumb/" . config("env.image_prefix") . "_" . uniqid() . Common::generateRandomString(7) . ".webp"; File::put($this->image_destination . $file_path, $data_img); $slide["Thumbnail"] = $file_path; $slideObject = $mgr->create($slide); TemplateJson::saveJson($slideObject->Id, $json_save); $result = array("status" => true); return response()->json($result); } catch (\Exception $e) { return response()->json(array("Internal server error")); } } public function zipFileAndDownload(Request $request) { try { $json_all = $request->get("json_all"); $master_json = $request->get("master_json"); $json_all = json_decode($json_all, true); $zip_json = new \ZipArchive(); $image_destination = config("env.image_destination"); $organizationId = Teacher::GetOrganizationId(); if (!File::isDirectory($image_destination . "/Slide/" . $organizationId)) { File::makeDirectory($image_destination . "/Slide/" . $organizationId); } $nameFormat = Common::GetFileName("/Slide/{$organizationId}", "/getSlide", "zip"); $zip_json->open($image_destination . $nameFormat["path"], \ZipArchive::CREATE); $zip_json->addFromString("slide_master.json", $master_json); $zip_json->setEncryptionName("slide_master.json", \ZipArchive::EM_AES_256, "edulive_secret"); foreach ($json_all as $key => $content) { $zip_json->addFromString($key . ".json", $content); $zip_json->setEncryptionName($key . ".json", \ZipArchive::EM_AES_256, "edulive_secret"); } $zip_json->close(); return response()->file($image_destination . $nameFormat["path"]); } catch (\Exception $e) { die; } } public function importZipFile(Request $request) { ini_set("memory_limit", -1); $zip_file = $request->file("zip_file"); $section_id = $request->get("section_id"); $this->checkPermission($section_id); $lesson = Lesson::where("Id", $section_id)->first(); try { $zip_json = new \ZipArchive(); $slide_mgr = new Slide(); $max_index = $slide_mgr->getMaxIndex($lesson->Id) + 1; $slide_master = ''; $open_result = $zip_json->open($zip_file->getRealPath()); if ($open_result === true) { $zip_json->setPassword("edulive_secret"); for ($i = 0; $i < $zip_json->numFiles; $i++) { if ($zip_json->getNameIndex($i) != "slide_master.json") { $slide_json = $zip_json->getFromIndex($i); $slideId = str_replace(".json", '', $zip_json->getNameIndex($i)); $data = array(); $data["Index"] = intval($max_index + $i); $data["Name"] = $lesson->Name; $data["Width"] = config("edulive.canvas_size"); $data["Height"] = config("edulive.canvas_size"); $data["Version"] = $lesson->ContentVersion; $data["Section_Id"] = $lesson->Id; $slide_obj = $slide_mgr->create($data); SlideJson::saveJson($slide_obj->Id, $slide_json); $json_decode = json_decode($slide_json, true); if (isset($json_decode["objects"])) { foreach ($json_decode["objects"] as $object) { if (isset($object["isAnimation"]) && $object["isAnimation"] == 1) { $animationMgr = new SlideAnimation(); $ani = SlideAnimation::where("SlideId", $slideId)->where("ObjectId", $object["ObjectId"])->first(); if (isset($ani)) { $data = array(); $data["SlideId"] = $slide_obj->Id; $data["ObjectId"] = $ani->ObjectId; $data["Type"] = $ani->Type; $data["Index"] = $ani->Index; $animationMgr->AddAnimation($data); } } } } } else { $slide_master = $zip_json->getFromIndex($i); } } $zip_json->close(); } else { return response()->json(array("status" => false, "message" => "Open error code: " . $open_result)); } return response()->json(array("status" => true, "master_json" => $slide_master)); } catch (\Exception $e) { return response()->json(array("status" => false, "message" => "Internal server error")); } } public function copySlideToCategory(Request $request) { try { $categoryId = $request->get("categoryId"); $json_save = $request->get("json_save"); $mgr = new TemplateContent(); $slide = array(); $slide["Index"] = 0; $slide["CategoryId"] = $categoryId; $slide["ContentJson"] = ''; $slide["Type"] = TemplateContent::SYSTEM; $slide["OwnerId"] = Teacher::GetTeacherId(); $thumb = $request->get("img_thumb"); $image_destination = config("env.image_destination"); if (!File::isDirectory($image_destination . "/TemplateThumb")) { File::makeDirectory($image_destination . "/TemplateThumb"); } $img = str_replace("data:image/webp;base64,", '', $thumb); $img = str_replace(" ", "+", $img); $data_img = base64_decode($img); $file_path = "/TemplateThumb/" . config("env.image_prefix") . "_" . uniqid() . Common::generateRandomString(7) . ".webp"; File::put($this->image_destination . $file_path, $data_img); $slide["Thumbnail"] = $file_path; $slideObject = $mgr->create($slide); TemplateJson::saveJson($slideObject->Id, $json_save); return response()->json(array("result" => 1, "message" => "This slide has added to this category successfully")); } catch (\Exception $exception) { return response()->json(array("result" => 0, "message" => "Internal server error")); } } public function replaceSlideTemplate(Request $request) { try { $replacedTemplateId = $request->get("replacedTemplateId"); $json_save = $request->get("json_save"); $thumb = $request->get("img_thumb"); $image_destination = config("env.image_destination"); if (!File::isDirectory($image_destination . "/TemplateThumb")) { File::makeDirectory($image_destination . "/TemplateThumb"); } $img = str_replace("data:image/webp;base64,", '', $thumb); $img = str_replace(" ", "+", $img); $data_img = base64_decode($img); $file_path = "/TemplateThumb/" . config("env.image_prefix") . "_" . uniqid() . Common::generateRandomString(7) . ".webp"; File::put($this->image_destination . $file_path, $data_img); $replacedTemplate = TemplateContent::findOrFail($replacedTemplateId); $replacedTemplate->Thumbnail = $file_path; $replacedTemplate->save(); TemplateJson::saveJson($replacedTemplateId, $json_save); return response()->json(array("result" => 1, "message" => "This template has been replaced successfully")); } catch (\Exception $exception) { return response()->json(array("result" => 0, "message" => "Internal server error")); } } public function updateThumnailTemplate(Request $request) { try { $templateId = $request->get("templateId"); $thumb = $request->get("img_thumb"); $image_destination = config("env.image_destination"); if (!File::isDirectory($image_destination . "/TemplateThumb")) { File::makeDirectory($image_destination . "/TemplateThumb"); } $img = str_replace("data:image/webp;base64,", '', $thumb); $img = str_replace(" ", "+", $img); $data_img = base64_decode($img); $file_path = "/TemplateThumb/" . config("env.image_prefix") . "_" . $templateId . uniqid() . Common::generateRandomString(7) . ".webp"; File::put($this->image_destination . $file_path, $data_img); $template = TemplateContent::findOrFail($templateId); $template->Thumbnail = $file_path; $template->save(); return response()->json(array("result" => 1, "message" => "This template has been replaced successfully")); } catch (\Exception $exception) { return response()->json(array("result" => 0, "message" => "Internal server error")); } } public function getSlideUrl() { $lessonId = Request()->get("id"); return response()->json(array("url" => $lessonId)); } public function updateResourceFromFileLibrary(Request $request) { $fileId = $request->get("id"); try { $data = array(); $libFile = LibraryFile::find($fileId); $libs = SlideResource::select(array("LibraryFile.Hash", "LibraryFile.FileName"))->join("LibraryFile", "SlideResource.LibraryFileId", "LibraryFile.Id")->where("SlideResource.TeacherId", Teacher::Current()->Id)->where("LibraryFile.DeletedFlag", 0)->where("SlideResource.DeletedFlag", 0)->whereNotNull("LibraryFile.Hash")->get(); $hashes = $libs->pluck("Hash")->toArray(); $hash = $libFile->Hash; if (in_array($hash, $hashes)) { $files = $libs->where("Hash", $hash)->pluck("FileName")->toArray(); return response()->json(array("result" => 0, "message" => __("lang.010216_75", array("file" => implode(", ", $files))))); } $data["Name"] = $libFile->FileName; $data["Type"] = SlideResource::RESOURCE_AUDIO; $data["Size"] = $libFile->Size; $converted = Common::copyFileToResource($libFile); $data["FileUrl"] = $converted["url"]; $data["TeacherId"] = Teacher::Current()->Id; $data["LibraryFileId"] = $fileId; SlideResource::create($data); return response()->json(array("result" => 1)); } catch (\Exception $exception) { return response()->json(array("result" => 0)); } } public function getUrlChangeAudio($audioId) { try { $audio = LibraryFile::find($audioId); $exec = Common::copyFileToResource($audio); $url = $exec["url"]; return response()->json(array("result" => 1, "url" => $url, "name" => $audio->FileName)); } catch (\Exception $exception) { return response()->json(array("result" => 0)); } } } ?>
Did this file decode correctly?
Original Code
<?php
namespace App\Http\Controllers; use App\Common; use App\Models\BackgroundCategory; use App\Models\Constant\PermissionConstant; use App\Models\DocumentEmbed; use App\Models\Lesson; use App\Models\LibraryFile; use App\Models\LibraryFileUserPermission; use App\Models\Slide; use App\Models\SlideAnimation; use App\Models\SlideAudio; use App\Models\SlideJson; use App\Models\SlideResource; use App\Models\SlideVideo; use App\Models\Teacher; use App\Models\TemplateCategory; use App\Models\TemplateContent; use App\Models\TemplateJson; use App\Models\Test\Category; use App\PermissionManager; use App\Util\EMp3; use FFMpeg\FFMpeg; use Illuminate\Http\Request; use Illuminate\Support\Facades\File; class SlideController extends ControllerTeacher { protected $image_destination; protected $upload_destination; public function __construct() { $this->middleware("\x61\x75\x74\150"); $this->upload_destination = config("\x65\x6e\x76\x2e\165\160\154\157\x61\144\137\144\145\x73\x74\x69\156\x61\x74\x69\x6f\x6e"); $this->image_destination = config("\145\x6e\x76\56\151\155\x61\147\145\137\x64\145\x73\x74\x69\x6e\x61\164\151\157\156"); } public function indexOld($lesson_id) { $lesson = Lesson::find($lesson_id); $slide_mgr = new Slide(); $select_arr = array("\111\x64", "\111\156\x64\145\170", "\116\141\155\145", "\x46\x69\154\145\125\162\154"); $slideList = $slide_mgr->getListSlideBySection($lesson->Id, $lesson->ContentVersion, $select_arr); $slide_template = TemplateCategory::GetAll(); $slide_background = BackgroundCategory::GetAll(); return view("\143\157\156\x74\145\x6e\x74\56\163\154\x69\144\145\56\155\141\x6b\x65", compact("\x73\x6c\151\144\x65\114\x69\163\164", "\163\x6c\x69\x64\x65\x5f\164\x65\x6d\160\x6c\x61\x74\145", "\x73\154\x69\144\x65\x5f\142\x61\143\x6b\x67\162\157\165\x6e\144", "\154\x65\x73\x73\157\156")); } public function index($lesson_id) { $this->checkPermission($lesson_id); $lesson = Lesson::find($lesson_id); $slide_mgr = new Slide(); $select_arr = array("\x49\x64", "\x49\156\144\145\170", "\116\141\155\x65", "\106\x69\154\145\125\x72\154"); $slideList = $slide_mgr->getListSlideBySection($lesson->Id, $lesson->ContentVersion, $select_arr); $slide_template = TemplateCategory::GetAll(); $slide_background = BackgroundCategory::GetAll(); return view("\142\x65\x74\x61\x2e\x63\157\156\164\x65\156\164\56\155\x61\x6b\145\x5f\x73\154\151\x64\x65\x2e\155\141\153\x65", compact("\x73\x6c\x69\144\x65\114\151\163\x74", "\163\154\151\144\145\x5f\x74\145\155\160\154\x61\164\x65", "\x73\x6c\151\144\x65\x5f\x62\141\143\153\x67\162\157\165\156\x64", "\x6c\x65\x73\163\x6f\156")); } public function indexNew($lesson_id) { $this->checkPermission($lesson_id); $lesson = Lesson::find($lesson_id); $slide_mgr = new Slide(); $select_arr = array("\x49\x64", "\x49\x6e\144\x65\x78", "\116\x61\155\145", "\106\x69\x6c\x65\x55\x72\154"); $slideList = $slide_mgr->getListSlideBySection($lesson->Id, $lesson->ContentVersion, $select_arr); $slide_template = TemplateCategory::GetAll(); $slide_background = BackgroundCategory::GetAll(); return view("\x62\x65\164\x61\x2e\143\x6f\156\x74\x65\x6e\x74\56\155\141\x6b\145\137\163\x6c\x69\x64\x65\x2e\x5f\156\145\x77\x2e\155\141\x6b\x65", compact("\163\x6c\151\x64\x65\x4c\151\x73\164", "\x73\154\x69\x64\x65\137\164\145\x6d\x70\154\141\164\145", "\x73\x6c\x69\x64\145\x5f\142\x61\x63\x6b\x67\162\157\165\x6e\x64", "\154\x65\x73\x73\157\x6e")); } function checkPermission($lesson_id, $slide_id = 0) { if (PermissionManager::IsAdmin()) { return true; } if ($lesson_id == 0) { $slide = Slide::find($slide_id); if (!isset($slide)) { abort(403); } $lesson_id = $slide->Section_Id; } $libFile = LibraryFile::where("\124\x79\x70\145", LibraryFile::TYPE_SLIDE)->where("\x4f\162\x67\141\156\151\x7a\x61\x74\151\x6f\156\x49\144", Teacher::GetOrganizationId())->where("\x43\x6f\x6e\164\x65\156\164\x49\x64", $lesson_id)->where("\x44\145\154\x65\x74\145\x64\x46\154\x61\147", 0)->first(); if (PermissionManager::IsOrganizationAdmin()) { if ($libFile->OrganizationId == Teacher::GetOrganizationId()) { return true; } } if ($libFile->OwnerId == 0 || $libFile->OwnerId == Teacher::Current()->Id) { return true; } $ids = array($libFile->Id, $libFile->P1, $libFile->P2, $libFile->P3, $libFile->P4); $ids = array_filter($ids, function ($item) { return $item > 0; }); $filePermission = LibraryFileUserPermission::whereIn("\106\x69\154\145\111\144", $ids)->where("\x55\163\x65\162\111\144", Teacher::Current()->Id)->where("\x41\x63\164\x69\x6f\156", LibraryFileUserPermission::ACTION_EDIT)->first(); if (isset($filePermission)) { return true; } abort(403); } public function revertSlideToVersion($lesson_id, $version) { if (!PermissionManager::IsAdmin()) { abort(404); } $lesson = Lesson::find($lesson_id); $currentSlides = $lesson->Slides(); $lastSlides = $lesson->SlidesWithVersion($version); $image_destination = config("\x65\x6e\x76\x2e\151\155\141\x67\x65\x5f\144\x65\x73\164\x69\x6e\x61\x74\x69\x6f\x6e"); foreach ($currentSlides as $currentSlide) { foreach ($lastSlides as $lastSlide) { if ($lastSlide->Index == $currentSlide->Index) { if (isset($lastSlide->FileJsonUrl)) { $json_save = file_get_contents($image_destination . $lastSlide->FileJsonUrl); SlideJson::saveJson($currentSlide->Id, $json_save); } } } } echo "\162\145\166\x65\162\x74\x20\x73\165\143\x63\x65\163\x73"; die; } public function revertAllSlide() { if (!PermissionManager::IsAdmin()) { abort(404); } $lessons = Lesson::where("\104\x65\154\145\x74\145\144\x46\154\x61\147", 0)->where("\122\x65\x76\x65\162\164\x53\x74\141\164\165\163", 0)->take(10)->get(); foreach ($lessons as $lesson) { $lastZip = $lesson->LastSlideZip(); if (isset($lastZip)) { $currentSlides = $lesson->Slides(); $lastSlides = $lesson->SlidesWithVersion($lastZip->Version); $image_destination = config("\x65\x6e\x76\x2e\x69\x6d\x61\147\x65\137\144\145\163\164\x69\156\141\x74\151\x6f\156"); foreach ($currentSlides as $currentSlide) { foreach ($lastSlides as $lastSlide) { if ($lastSlide->Index == $currentSlide->Index) { if (isset($lastSlide->FileJsonUrl)) { $json_save = file_get_contents($image_destination . $lastSlide->FileJsonUrl); SlideJson::saveJson($currentSlide->Id, $json_save); } } } } } $lesson->RevertStatus = 1; $lesson->save(); } echo "\x72\145\x76\x65\x72\164\40\x73\x75\x63\x63\x65\x73\163"; die; } public function createSlideAudio(Request $request) { try { $this->checkPermission(0, $request->get("\163\154\151\144\x65\137\151\x64")); $organizationId = Teacher::GetOrganizationId(); if (!File::isDirectory($this->upload_destination . "\x2f" . $organizationId)) { File::makeDirectory($this->upload_destination . "\57" . $organizationId); } $data = array(); $audio = $request->file("\x73\x6c\151\144\145\x5f\141\x75\144\151\157"); $start_time = $request->get("\x73\x74\x61\x72\x74\x5f\164\151\155\145"); $end_time = $request->get("\x65\156\144\137\164\x69\x6d\x65"); $file_etc = $audio->getClientOriginalExtension(); $time = uniqid() . Common::generateRandomString(7); $data["\123\x6c\x69\x64\x65\x5f\111\x64"] = $request->get("\x73\154\x69\144\145\137\x69\144"); $data["\x54\157\x70"] = 20; $data["\122\x69\x67\150\x74"] = 30; $data["\x4c\145\146\164"] = 20; $data["\x42\157\164\164\x6f\155"] = 30; $data["\123\x69\172\x65"] = round($audio->getSize() / 1024); Common::IncreaseStorage($organizationId, $data["\123\x69\x7a\x65"]); $audio_url = $organizationId . "\57" . "{$time}\x2e\155\x70\63"; if (substr(php_uname(), 0, 7) == "\x57\151\x6e\144\x6f\167\163") { $ffmpeg = FFMpeg::create(array("\x66\146\x6d\x70\145\x67\x2e\142\151\156\141\x72\151\x65\x73" => config("\x65\x6e\166\56\x66\x66\155\160\145\x67\137\160\141\164\150") . "\x66\x66\x6d\x70\145\x67\x2e\145\x78\x65", "\x66\146\x70\x72\x6f\142\145\56\142\151\156\141\x72\x69\145\x73" => config("\145\156\166\x2e\x66\146\155\x70\145\147\137\160\141\x74\150") . "\x66\x66\160\162\x6f\x62\145\x2e\145\x78\x65", "\x74\x69\x6d\145\157\165\x74" => 3600, "\146\146\x6d\160\145\147\x2e\x74\x68\x72\x65\x61\x64\163" => 12)); } else { $ffmpeg = FFMpeg::create(array("\x66\x66\155\160\x65\x67\x2e\142\x69\156\141\162\151\145\163" => config("\x65\x6e\x76\x2e\146\146\x6d\x70\x65\x67\x5f\160\141\x74\150") . "\146\146\155\160\x65\x67", "\146\x66\160\x72\x6f\142\145\56\142\x69\156\x61\x72\x69\x65\x73" => config("\x65\x6e\166\56\x66\x66\x6d\x70\145\147\137\160\141\164\x68") . "\x66\x66\160\x72\x6f\x62\x65", "\164\151\x6d\145\157\165\164" => 3600, "\x66\146\155\x70\x65\147\x2e\164\150\x72\145\x61\x64\163" => 12)); } $audio_ff = $ffmpeg->open($audio->getRealPath()); $duration = $ffmpeg->getFFProbe()->format($audio->getRealPath())->get("\144\x75\x72\141\x74\x69\157\x6e"); $format = new EMp3(); $audio_ff->save($format, config("\x65\x6e\166\56\x75\160\154\x6f\141\x64\x5f\x64\145\163\164\151\x6e\x61\164\151\157\156") . "\57{$audio_url}"); $data["\x55\x72\x6c"] = $audio_url; $audio = SlideAudio::create($data); $result = array("\x41\165\x64\x69\157\x5f\111\x64" => $audio->Id, "\125\162\154" => $audio->Url, "\104\165\162\x61\164\x69\x6f\x6e" => $duration, "\x53\x69\x7a\145" => $data["\123\x69\x7a\145"]); return response()->json($result); } catch (\Exception $e) { return response()->json(array("\x49\156\164\145\162\x6e\141\154\40\163\145\162\x76\x65\x72\x20\x65\162\x72\x6f\162")); } } public function createSlideVideo(Request $request) { try { $this->checkPermission(0, $request->get("\x73\154\x69\144\145\x5f\151\x64")); $organizationId = Teacher::GetOrganizationId(); if (!File::isDirectory($this->upload_destination . "\57" . $organizationId)) { File::makeDirectory($this->upload_destination . "\x2f" . $organizationId); } $video = $request->file("\163\x6c\x69\x64\x65\x5f\x76\151\x64\x65\157"); $file_etc = $video->getClientOriginalExtension(); $time = uniqid() . Common::generateRandomString(7); $slide_id = $request->get("\x73\154\x69\x64\x65\137\x69\x64"); $data = array(); $data["\x53\x6c\x69\144\x65\x5f\x49\144"] = $slide_id; $data["\124\157\x70"] = 20; $data["\122\x69\147\150\164"] = 40; $data["\114\x65\146\x74"] = 20; $data["\x42\157\164\x74\x6f\x6d"] = 40; $data["\x53\x69\172\x65"] = round($video->getSize() / 1024); Common::IncreaseStorage($organizationId, $data["\123\x69\172\x65"]); $data["\125\x72\154"] = $organizationId . "\57" . "{$time}\56{$file_etc}"; $video->move($this->upload_destination . "\x2f" . $organizationId, "{$time}\x2e{$file_etc}"); $audio = SlideVideo::create($data); $data["\126\151\x64\145\x6f\137\x49\x64"] = $audio->Id; return response()->json($data); } catch (\Exception $e) { return response()->json(''); } } public function updateSlideAudio(Request $request) { $audio_id = $request->get("\141\165\x64\x69\x6f\137\151\144"); $top = $request->get("\164\157\160"); $left = $request->get("\x6c\145\146\x74"); $right = $request->get("\x72\151\x67\150\x74"); $bottom = $request->get("\142\157\164\x74\157\155"); $audio = SlideAudio::find($audio_id); if (isset($audio)) { $audio->Top = $top; $audio->Right = $right; $audio->Left = $left; $audio->Bottom = $bottom; $audio->update(); } return response()->json("\165\x70\144\x61\x74\145\40\x6f\153"); } public function updateSlideVideo(Request $request) { $video_id = $request->get("\x76\151\144\x65\157\x5f\x69\144"); $top = $request->get("\x74\x6f\x70"); $left = $request->get("\x6c\145\x66\164"); $right = $request->get("\x72\x69\147\150\x74"); $bottom = $request->get("\142\157\164\164\x6f\155"); $video = SlideVideo::find($video_id); if (isset($video)) { $video->Top = $top; $video->Right = $right; $video->Left = $left; $video->Bottom = $bottom; $video->save(); } return response()->json("\x75\x70\144\x61\x74\x65\x20\157\x6b"); } public function deleteSlideAudio(Request $request) { $audio_id = $request->get("\141\165\144\151\157\x5f\x69\144"); $audio = SlideAudio::find($audio_id); Common::DecreaseStorage(Teacher::GetOrganizationId(), $audio->Size); $audio->delete(); return response()->json("\144\145\154\145\x74\x65\40\157\153"); } public function deleteSlideVideo(Request $request) { $video_id = $request->get("\166\x69\x64\x65\x6f\x5f\x69\144"); $video = SlideVideo::find($video_id); Common::DecreaseStorage(Teacher::GetOrganizationId(), $video->Size); $video->delete(); return response()->json("\x64\145\x6c\x65\x74\x65\40\x6f\x6b"); } public function getJsonTemplate(Request $request) { $template_id = $request->get("\x74\145\155\160\154\141\164\x65\x49\x64"); $template = TemplateContent::find($template_id); if (isset($template)) { $contentJson = TemplateJson::getContentJson($template_id); $json_str = $contentJson != '' ? $contentJson : Common::SlideDefault(); return response()->json(array("\164\x65\155\160\x6c\x61\x74\x65\x4a\x73\x6f\156" => $json_str)); } return response()->json(array("\164\x65\x6d\x70\x6c\141\x74\x65\112\x73\157\x6e" => Common::SlideDefault())); } public function sbUploadAudio(Request $request) { try { $this->checkPermission(0, $request->get("\x73\154\x69\x64\x65\137\x69\x64")); $data = array(); $file_name = $request->get("\x66\151\x6c\145\137\x6e\x61\x6d\145"); $data["\123\x6c\151\144\x65\137\x49\x64"] = $request->get("\x73\154\x69\144\145\x5f\x69\144"); $data["\x54\x6f\160"] = 20; $data["\x52\151\x67\150\164"] = 30; $data["\114\x65\x66\x74"] = 20; $data["\102\x6f\x74\164\x6f\155"] = 30; $data["\125\162\154"] = $file_name; $audio = SlideAudio::create($data); $result = array("\x73\x74\x61\x74\x75\x73" => true, "\x41\x75\x64\151\157\x5f\111\x64" => $audio->Id, "\x55\x72\x6c" => $audio->Url); return response()->json($result); } catch (\Exception $e) { return response()->json(array("\x73\164\x61\x74\165\163" => false, "\155\x65\163\x73\x61\147\145" => "\111\x6e\164\145\162\x6e\141\x6c\x20\x73\x65\162\x76\x65\x72\x20\145\x72\162\157\162")); } } public function sbUploadVideo(Request $request) { try { $this->checkPermission(0, $request->get("\x73\154\151\144\x65\x5f\151\x64")); $data = array(); $file_name = $request->get("\146\151\x6c\x65\x5f\x6e\141\x6d\145"); $filePath = config("\x65\x6e\166\x2e\x75\x70\154\157\141\x64\137\144\x65\163\164\x69\156\141\x74\151\x6f\x6e") . "\57" . $file_name; $slide_id = $request->get("\x73\x6c\x69\144\145\137\x69\x64"); $data["\123\154\151\x64\x65\137\x49\144"] = $slide_id; $data["\x54\157\160"] = 20; $data["\122\151\147\x68\164"] = 40; $data["\114\145\146\164"] = 20; $data["\x42\x6f\x74\164\157\x6d"] = 40; $data["\x55\162\154"] = $file_name; $audio = SlideVideo::create($data); $data["\x56\x69\x64\145\x6f\x5f\x49\144"] = $audio->Id; $data["\x73\164\x61\164\165\x73"] = true; return response()->json($data); } catch (\Exception $e) { return response()->json(array("\x73\164\x61\x74\165\x73" => false, "\x6d\145\x73\163\141\147\x65" => "\x49\156\x74\x65\162\x6e\x61\x6c\40\163\145\162\x76\145\162\40\145\162\x72\157\x72")); } } public function createSlideResource(Request $request) { try { $data = array(); $resource = $request->file("\x72\145\163\157\165\162\x63\145"); $data["\116\x61\x6d\x65"] = $request->get("\x6e\x61\155\145"); $data["\124\171\x70\x65"] = SlideResource::RESOURCE_AUDIO; $data["\123\151\x7a\145"] = round($resource->getSize() / 1024); $data["\124\x65\141\x63\150\145\162\x49\x64"] = Teacher::GetTeacherId(); $organizationId = Teacher::GetOrganizationId(); Common::IncreaseStorage($organizationId, $data["\x53\x69\x7a\145"]); $time = uniqid() . Common::generateRandomString(7); $audio_url = "{$time}\56\155\160\63"; if (substr(php_uname(), 0, 7) == "\x57\151\156\144\157\x77\163") { $ffmpeg = FFMpeg::create(array("\x66\146\x6d\160\145\x67\56\x62\151\x6e\141\162\151\145\163" => config("\145\x6e\166\x2e\146\146\x6d\x70\145\147\x5f\x70\x61\x74\150") . "\x66\146\155\x70\x65\x67\56\x65\x78\145", "\x66\146\x70\162\157\142\145\x2e\142\x69\156\141\x72\x69\145\x73" => config("\145\156\x76\x2e\146\146\155\160\x65\x67\137\160\141\x74\x68") . "\x66\x66\x70\x72\157\x62\x65\x2e\x65\170\x65", "\164\x69\x6d\x65\x6f\165\164" => 3600, "\146\146\x6d\160\145\x67\x2e\164\x68\x72\x65\x61\144\x73" => 12)); } else { $ffmpeg = FFMpeg::create(array("\x66\x66\155\x70\145\x67\56\x62\151\x6e\141\x72\151\145\163" => config("\x65\x6e\166\x2e\x66\x66\x6d\160\145\x67\x5f\160\141\164\150") . "\x66\146\155\160\x65\x67", "\146\146\160\x72\157\x62\145\x2e\x62\151\x6e\x61\x72\x69\x65\x73" => config("\145\x6e\166\56\x66\x66\155\160\145\x67\137\x70\x61\x74\x68") . "\x66\146\160\x72\x6f\x62\145", "\x74\x69\155\145\157\165\x74" => 3600, "\146\x66\155\x70\145\147\56\x74\x68\x72\x65\141\x64\163" => 12)); } $audio_ff = $ffmpeg->open($resource->getRealPath()); $format = new EMp3(); $file_path = public_path() . "\x2f\162\145\163\157\x75\x72\143\145\57" . $organizationId; if (!File::isDirectory(public_path() . "\x2f\162\x65\163\x6f\x75\x72\x63\x65")) { File::makeDirectory(public_path() . "\x2f\x72\x65\163\x6f\165\162\143\x65"); } if (!File::isDirectory($file_path)) { File::makeDirectory($file_path); } $audio_ff->save($format, $file_path . "\57{$audio_url}"); $data["\106\151\x6c\x65\125\x72\154"] = "\x2f\162\x65\x73\x6f\165\162\x63\145\57{$organizationId}\57{$audio_url}"; SlideResource::create($data); $result = array("\163\x74\141\164\165\x73" => true); return response()->json($result); } catch (\Exception $e) { return response()->json(array("\111\x6e\164\145\162\156\x61\154\40\163\145\162\166\145\162\x20\x65\162\162\157\162")); } } public function getAllResource() { return response()->json(SlideResource::GetAll()->toArray()); } public function deleteResource(Request $request) { $resourceId = $request->get("\x72\145\163\x6f\x75\x72\143\145\137\151\144"); $resource = SlideResource::find($resourceId); if (isset($resourceId)) { $resource->DeletedFlag = 1; $resource->save(); } return response()->json(array("\163\164\141\164\x75\x73", true)); } public function saveToMyTemplate(Request $request) { try { $json_save = $request->get("\152\x73\157\x6e\137\163\x61\166\x65"); $mgr = new TemplateContent(); $slide = array(); $slide["\111\156\144\145\x78"] = 0; $slide["\x43\x61\164\x65\x67\157\x72\x79\111\x64"] = 0; $slide["\x43\157\156\x74\x65\x6e\164\112\163\157\156"] = ''; $slide["\124\x79\160\145"] = TemplateContent::TEACHER; $slide["\x4f\x77\x6e\x65\162\111\x64"] = Teacher::GetTeacherId(); $thumb = $request->get("\x69\155\147\137\164\150\x75\x6d\142"); $image_destination = config("\145\x6e\166\56\151\x6d\141\x67\145\137\144\145\163\164\151\x6e\141\x74\x69\x6f\x6e"); if (!File::isDirectory($image_destination . "\x2f\124\x65\x6d\x70\154\x61\x74\145\124\x68\x75\155\x62")) { File::makeDirectory($image_destination . "\57\x54\x65\155\x70\x6c\x61\164\x65\x54\150\x75\155\x62"); } $img = str_replace("\x64\141\x74\x61\x3a\151\x6d\x61\x67\145\57\x77\145\x62\x70\73\142\x61\163\x65\x36\64\x2c", '', $thumb); $img = str_replace("\40", "\x2b", $img); $data_img = base64_decode($img); $file_path = "\57\x54\145\x6d\x70\154\x61\x74\x65\x54\x68\165\x6d\142\x2f" . config("\145\x6e\x76\56\151\155\x61\147\145\137\x70\x72\x65\x66\x69\170") . "\137" . uniqid() . Common::generateRandomString(7) . "\56\x77\145\142\x70"; File::put($this->image_destination . $file_path, $data_img); $slide["\x54\x68\x75\x6d\x62\156\141\151\154"] = $file_path; $slideObject = $mgr->create($slide); TemplateJson::saveJson($slideObject->Id, $json_save); $result = array("\x73\164\141\x74\x75\163" => true); return response()->json($result); } catch (\Exception $e) { return response()->json(array("\x49\156\x74\x65\162\x6e\x61\154\x20\x73\145\x72\x76\x65\162\x20\x65\x72\162\157\162")); } } public function saveToOrganizationTemplate(Request $request) { try { $json_save = $request->get("\x6a\163\x6f\x6e\x5f\163\141\166\145"); $mgr = new TemplateContent(); $slide = array(); $slide["\111\156\144\x65\x78"] = 0; $slide["\x43\141\x74\145\x67\157\162\x79\111\x64"] = 0; $slide["\x43\157\x6e\x74\145\156\x74\x4a\x73\x6f\156"] = ''; $slide["\x54\171\x70\x65"] = TemplateContent::ORGANIZATION; $slide["\117\167\156\x65\162\x49\144"] = Teacher::GetOrganizationId(); $thumb = $request->get("\x69\155\147\137\164\x68\165\155\x62"); $image_destination = config("\x65\156\166\56\x69\155\141\147\145\x5f\144\x65\163\164\151\156\x61\164\151\x6f\156"); if (!File::isDirectory($image_destination . "\57\x54\145\155\x70\x6c\141\164\x65\x54\x68\165\155\142")) { File::makeDirectory($image_destination . "\57\124\x65\x6d\160\x6c\x61\164\x65\124\150\x75\155\142"); } $img = str_replace("\144\141\164\141\72\x69\x6d\x61\147\145\x2f\x77\145\x62\160\73\x62\141\x73\x65\x36\64\x2c", '', $thumb); $img = str_replace("\x20", "\x2b", $img); $data_img = base64_decode($img); $file_path = "\x2f\124\x65\155\x70\x6c\141\164\x65\124\x68\x75\x6d\142\x2f" . config("\145\x6e\x76\x2e\x69\155\x61\147\x65\137\160\162\x65\146\x69\x78") . "\137" . uniqid() . Common::generateRandomString(7) . "\56\x77\145\142\160"; File::put($this->image_destination . $file_path, $data_img); $slide["\x54\x68\165\155\x62\x6e\141\x69\154"] = $file_path; $slideObject = $mgr->create($slide); TemplateJson::saveJson($slideObject->Id, $json_save); $result = array("\163\164\x61\164\x75\163" => true); return response()->json($result); } catch (\Exception $e) { return response()->json(array("\111\156\x74\x65\162\x6e\x61\154\40\163\x65\162\166\x65\x72\40\x65\x72\162\x6f\x72")); } } public function zipFileAndDownload(Request $request) { try { $json_all = $request->get("\152\163\x6f\x6e\x5f\141\x6c\154"); $master_json = $request->get("\x6d\141\163\164\x65\162\137\x6a\x73\157\156"); $json_all = json_decode($json_all, true); $zip_json = new \ZipArchive(); $image_destination = config("\x65\156\166\x2e\x69\x6d\141\x67\145\137\144\x65\163\x74\x69\x6e\141\x74\151\157\x6e"); $organizationId = Teacher::GetOrganizationId(); if (!File::isDirectory($image_destination . "\57\x53\x6c\151\144\145\x2f" . $organizationId)) { File::makeDirectory($image_destination . "\57\123\x6c\151\144\145\x2f" . $organizationId); } $nameFormat = Common::GetFileName("\57\123\154\151\144\145\57{$organizationId}", "\x2f\x67\x65\x74\123\154\x69\x64\145", "\x7a\151\160"); $zip_json->open($image_destination . $nameFormat["\x70\x61\x74\x68"], \ZipArchive::CREATE); $zip_json->addFromString("\x73\154\x69\144\x65\137\155\141\x73\x74\145\x72\56\x6a\163\x6f\x6e", $master_json); $zip_json->setEncryptionName("\x73\154\151\x64\145\137\155\141\163\x74\145\x72\x2e\x6a\163\157\156", \ZipArchive::EM_AES_256, "\145\144\x75\x6c\151\x76\x65\x5f\x73\x65\143\162\x65\x74"); foreach ($json_all as $key => $content) { $zip_json->addFromString($key . "\56\152\x73\x6f\156", $content); $zip_json->setEncryptionName($key . "\56\x6a\163\157\156", \ZipArchive::EM_AES_256, "\x65\x64\x75\x6c\x69\166\x65\137\163\145\143\x72\145\x74"); } $zip_json->close(); return response()->file($image_destination . $nameFormat["\160\141\164\x68"]); } catch (\Exception $e) { die; } } public function importZipFile(Request $request) { ini_set("\x6d\x65\x6d\157\x72\171\x5f\x6c\151\155\151\164", -1); $zip_file = $request->file("\172\151\x70\137\146\x69\154\x65"); $section_id = $request->get("\163\145\x63\x74\x69\157\156\x5f\x69\x64"); $this->checkPermission($section_id); $lesson = Lesson::where("\x49\144", $section_id)->first(); try { $zip_json = new \ZipArchive(); $slide_mgr = new Slide(); $max_index = $slide_mgr->getMaxIndex($lesson->Id) + 1; $slide_master = ''; $open_result = $zip_json->open($zip_file->getRealPath()); if ($open_result === true) { $zip_json->setPassword("\145\144\165\154\x69\166\145\137\163\145\x63\162\x65\x74"); for ($i = 0; $i < $zip_json->numFiles; $i++) { if ($zip_json->getNameIndex($i) != "\x73\x6c\151\144\145\137\x6d\141\x73\164\145\162\56\x6a\x73\x6f\x6e") { $slide_json = $zip_json->getFromIndex($i); $slideId = str_replace("\x2e\x6a\163\157\156", '', $zip_json->getNameIndex($i)); $data = array(); $data["\x49\156\144\x65\170"] = intval($max_index + $i); $data["\116\141\155\145"] = $lesson->Name; $data["\127\x69\x64\x74\150"] = config("\x65\144\165\154\151\166\x65\x2e\143\x61\156\166\141\x73\x5f\163\x69\x7a\x65"); $data["\x48\x65\x69\x67\150\x74"] = config("\x65\144\165\154\151\166\145\x2e\x63\141\156\166\141\x73\137\x73\x69\172\x65"); $data["\126\145\162\163\151\157\x6e"] = $lesson->ContentVersion; $data["\x53\145\x63\x74\x69\x6f\x6e\x5f\x49\x64"] = $lesson->Id; $slide_obj = $slide_mgr->create($data); SlideJson::saveJson($slide_obj->Id, $slide_json); $json_decode = json_decode($slide_json, true); if (isset($json_decode["\157\x62\x6a\145\x63\164\x73"])) { foreach ($json_decode["\157\x62\152\x65\143\164\x73"] as $object) { if (isset($object["\x69\163\x41\x6e\x69\155\x61\x74\x69\x6f\156"]) && $object["\x69\163\101\156\x69\x6d\141\x74\151\x6f\x6e"] == 1) { $animationMgr = new SlideAnimation(); $ani = SlideAnimation::where("\x53\x6c\151\144\x65\111\x64", $slideId)->where("\x4f\x62\152\145\x63\x74\x49\144", $object["\x4f\x62\152\145\143\164\x49\144"])->first(); if (isset($ani)) { $data = array(); $data["\123\x6c\x69\x64\x65\x49\x64"] = $slide_obj->Id; $data["\x4f\x62\152\145\x63\164\111\x64"] = $ani->ObjectId; $data["\124\171\160\145"] = $ani->Type; $data["\x49\x6e\x64\145\170"] = $ani->Index; $animationMgr->AddAnimation($data); } } } } } else { $slide_master = $zip_json->getFromIndex($i); } } $zip_json->close(); } else { return response()->json(array("\163\x74\141\164\165\163" => false, "\x6d\x65\x73\x73\141\x67\145" => "\x4f\x70\x65\x6e\x20\145\162\162\157\162\40\x63\x6f\144\145\x3a\40" . $open_result)); } return response()->json(array("\163\164\141\x74\165\x73" => true, "\x6d\141\x73\x74\145\x72\137\152\x73\157\156" => $slide_master)); } catch (\Exception $e) { return response()->json(array("\x73\x74\141\164\165\x73" => false, "\155\145\x73\163\141\147\145" => "\111\x6e\164\x65\x72\x6e\141\154\40\x73\145\162\x76\145\162\40\145\162\162\157\x72")); } } public function copySlideToCategory(Request $request) { try { $categoryId = $request->get("\x63\x61\x74\x65\x67\157\162\x79\111\x64"); $json_save = $request->get("\x6a\163\x6f\156\x5f\163\141\x76\x65"); $mgr = new TemplateContent(); $slide = array(); $slide["\x49\156\x64\x65\x78"] = 0; $slide["\103\141\x74\x65\147\157\162\x79\111\144"] = $categoryId; $slide["\103\157\156\164\145\156\164\112\x73\157\x6e"] = ''; $slide["\124\171\x70\x65"] = TemplateContent::SYSTEM; $slide["\117\x77\156\x65\162\111\144"] = Teacher::GetTeacherId(); $thumb = $request->get("\151\155\x67\x5f\x74\x68\x75\x6d\x62"); $image_destination = config("\145\156\x76\56\x69\155\141\x67\x65\137\144\145\163\164\x69\156\141\164\x69\x6f\156"); if (!File::isDirectory($image_destination . "\57\124\145\x6d\160\x6c\141\164\145\124\150\x75\155\142")) { File::makeDirectory($image_destination . "\57\124\x65\x6d\x70\154\x61\x74\x65\x54\x68\x75\155\x62"); } $img = str_replace("\x64\x61\x74\141\72\151\x6d\141\147\x65\57\167\x65\142\x70\x3b\142\141\x73\145\x36\64\54", '', $thumb); $img = str_replace("\40", "\53", $img); $data_img = base64_decode($img); $file_path = "\x2f\124\145\155\x70\x6c\x61\164\x65\x54\x68\x75\x6d\x62\57" . config("\x65\x6e\x76\x2e\151\155\x61\x67\x65\x5f\x70\x72\145\x66\x69\170") . "\137" . uniqid() . Common::generateRandomString(7) . "\x2e\x77\x65\142\160"; File::put($this->image_destination . $file_path, $data_img); $slide["\124\150\x75\155\142\x6e\141\151\154"] = $file_path; $slideObject = $mgr->create($slide); TemplateJson::saveJson($slideObject->Id, $json_save); return response()->json(array("\x72\145\163\x75\154\x74" => 1, "\x6d\x65\163\x73\x61\147\x65" => "\124\150\x69\x73\x20\163\154\151\144\x65\x20\150\141\163\x20\x61\x64\144\145\144\40\164\157\x20\164\x68\x69\x73\40\143\x61\x74\145\147\x6f\x72\x79\x20\x73\165\143\x63\145\x73\x73\146\x75\x6c\x6c\171")); } catch (\Exception $exception) { return response()->json(array("\162\x65\x73\x75\154\164" => 0, "\x6d\145\x73\163\x61\147\x65" => "\111\156\x74\x65\x72\156\141\x6c\40\163\x65\162\x76\x65\162\x20\x65\162\162\x6f\162")); } } public function replaceSlideTemplate(Request $request) { try { $replacedTemplateId = $request->get("\162\x65\160\154\141\x63\x65\x64\x54\x65\x6d\160\154\x61\164\x65\x49\144"); $json_save = $request->get("\x6a\163\157\x6e\x5f\x73\x61\166\145"); $thumb = $request->get("\151\x6d\x67\137\x74\150\x75\155\x62"); $image_destination = config("\x65\x6e\x76\56\x69\155\x61\147\145\x5f\x64\145\x73\x74\x69\156\141\164\x69\157\156"); if (!File::isDirectory($image_destination . "\x2f\x54\x65\155\160\x6c\x61\164\145\124\150\x75\155\142")) { File::makeDirectory($image_destination . "\x2f\124\145\155\x70\x6c\x61\x74\x65\x54\x68\165\x6d\x62"); } $img = str_replace("\x64\141\x74\141\72\x69\155\x61\147\x65\x2f\x77\x65\x62\160\x3b\x62\x61\x73\x65\66\x34\x2c", '', $thumb); $img = str_replace("\x20", "\x2b", $img); $data_img = base64_decode($img); $file_path = "\x2f\124\x65\x6d\x70\154\x61\164\145\x54\x68\165\x6d\x62\x2f" . config("\x65\156\x76\56\151\155\x61\x67\x65\x5f\x70\x72\x65\146\151\170") . "\137" . uniqid() . Common::generateRandomString(7) . "\56\167\x65\x62\x70"; File::put($this->image_destination . $file_path, $data_img); $replacedTemplate = TemplateContent::findOrFail($replacedTemplateId); $replacedTemplate->Thumbnail = $file_path; $replacedTemplate->save(); TemplateJson::saveJson($replacedTemplateId, $json_save); return response()->json(array("\x72\x65\163\x75\x6c\x74" => 1, "\155\145\163\x73\141\147\145" => "\x54\150\x69\163\x20\164\x65\155\x70\x6c\x61\x74\x65\40\150\x61\x73\x20\142\x65\145\156\40\x72\x65\x70\x6c\141\143\x65\144\x20\163\x75\143\143\x65\x73\163\x66\x75\154\154\171")); } catch (\Exception $exception) { return response()->json(array("\162\x65\163\165\x6c\164" => 0, "\x6d\145\x73\163\x61\147\145" => "\111\156\x74\145\162\x6e\141\154\x20\163\145\x72\x76\x65\162\x20\145\162\x72\x6f\162")); } } public function updateThumnailTemplate(Request $request) { try { $templateId = $request->get("\164\x65\x6d\x70\154\x61\x74\x65\111\144"); $thumb = $request->get("\x69\155\147\137\x74\x68\165\x6d\x62"); $image_destination = config("\145\x6e\x76\x2e\x69\155\x61\x67\x65\x5f\144\x65\x73\x74\x69\156\x61\164\151\157\x6e"); if (!File::isDirectory($image_destination . "\57\x54\x65\155\x70\x6c\141\164\145\124\150\165\x6d\142")) { File::makeDirectory($image_destination . "\x2f\124\x65\x6d\160\x6c\x61\x74\x65\x54\x68\165\155\x62"); } $img = str_replace("\x64\x61\164\x61\72\151\x6d\x61\147\x65\57\x77\145\142\160\73\x62\x61\x73\x65\x36\64\x2c", '', $thumb); $img = str_replace("\40", "\53", $img); $data_img = base64_decode($img); $file_path = "\57\x54\x65\x6d\x70\x6c\141\164\145\124\x68\165\x6d\142\57" . config("\x65\x6e\x76\x2e\151\x6d\x61\x67\145\x5f\x70\162\x65\146\x69\x78") . "\x5f" . $templateId . uniqid() . Common::generateRandomString(7) . "\x2e\x77\145\142\x70"; File::put($this->image_destination . $file_path, $data_img); $template = TemplateContent::findOrFail($templateId); $template->Thumbnail = $file_path; $template->save(); return response()->json(array("\162\145\163\x75\154\164" => 1, "\155\145\163\x73\141\147\145" => "\x54\150\151\163\40\164\145\x6d\160\154\141\164\x65\x20\x68\141\163\x20\x62\145\145\x6e\40\162\x65\160\154\x61\143\145\144\x20\163\x75\x63\143\145\x73\x73\146\165\154\x6c\171")); } catch (\Exception $exception) { return response()->json(array("\x72\145\163\165\x6c\164" => 0, "\155\145\x73\x73\x61\x67\145" => "\x49\x6e\164\145\x72\x6e\141\154\x20\163\x65\162\x76\x65\162\x20\x65\162\162\157\162")); } } public function getSlideUrl() { $lessonId = Request()->get("\151\x64"); return response()->json(array("\165\x72\154" => $lessonId)); } public function updateResourceFromFileLibrary(Request $request) { $fileId = $request->get("\151\x64"); try { $data = array(); $libFile = LibraryFile::find($fileId); $libs = SlideResource::select(array("\x4c\151\x62\x72\141\x72\x79\106\151\154\x65\56\x48\141\163\150", "\114\151\x62\x72\x61\x72\171\106\151\154\145\56\x46\151\154\x65\x4e\141\155\x65"))->join("\114\151\142\162\141\162\171\x46\151\x6c\x65", "\x53\154\x69\144\x65\x52\x65\163\x6f\165\x72\x63\145\x2e\x4c\x69\x62\x72\141\162\171\106\151\154\145\111\144", "\114\x69\x62\x72\141\162\171\106\151\x6c\145\56\111\x64")->where("\x53\x6c\x69\x64\145\x52\145\x73\157\x75\x72\x63\145\56\x54\145\x61\x63\150\145\x72\111\144", Teacher::Current()->Id)->where("\x4c\151\142\x72\x61\x72\x79\106\x69\x6c\145\x2e\x44\x65\x6c\145\164\x65\x64\106\x6c\141\x67", 0)->where("\123\154\x69\x64\x65\122\145\163\157\165\x72\x63\145\x2e\104\x65\154\145\164\x65\x64\106\x6c\141\x67", 0)->whereNotNull("\x4c\x69\x62\x72\x61\x72\x79\106\151\154\x65\56\110\x61\x73\x68")->get(); $hashes = $libs->pluck("\x48\141\163\x68")->toArray(); $hash = $libFile->Hash; if (in_array($hash, $hashes)) { $files = $libs->where("\x48\141\163\x68", $hash)->pluck("\x46\x69\x6c\145\x4e\141\155\145")->toArray(); return response()->json(array("\162\145\163\165\154\x74" => 0, "\x6d\x65\x73\163\141\147\145" => __("\x6c\x61\156\x67\x2e\60\x31\x30\x32\61\x36\x5f\67\x35", array("\146\151\154\x65" => implode("\x2c\x20", $files))))); } $data["\x4e\141\x6d\x65"] = $libFile->FileName; $data["\124\x79\160\145"] = SlideResource::RESOURCE_AUDIO; $data["\x53\151\x7a\x65"] = $libFile->Size; $converted = Common::copyFileToResource($libFile); $data["\x46\x69\x6c\x65\125\x72\x6c"] = $converted["\165\x72\154"]; $data["\124\145\141\143\x68\145\x72\111\144"] = Teacher::Current()->Id; $data["\114\151\x62\162\141\162\171\106\151\x6c\145\x49\144"] = $fileId; SlideResource::create($data); return response()->json(array("\x72\x65\163\x75\154\164" => 1)); } catch (\Exception $exception) { return response()->json(array("\162\145\163\x75\x6c\x74" => 0)); } } public function getUrlChangeAudio($audioId) { try { $audio = LibraryFile::find($audioId); $exec = Common::copyFileToResource($audio); $url = $exec["\165\162\154"]; return response()->json(array("\162\145\x73\165\x6c\164" => 1, "\x75\x72\154" => $url, "\x6e\x61\x6d\x65" => $audio->FileName)); } catch (\Exception $exception) { return response()->json(array("\162\145\163\165\154\x74" => 0)); } } }
Function Calls
None |
Stats
MD5 | 29690b3ac14e841b6e15dc119d6b18a6 |
Eval Count | 0 |
Decode Time | 214 ms |