ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMobMultiSrtUpload.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $lng;
18
19 protected $lm;
20
26 public function __construct(ilMobMultiSrtInt $a_multi_srt)
27 {
28 global $DIC;
29
30 $lng = $DIC->language();
31
32 $this->lng = $lng;
33 $this->multi_srt = $a_multi_srt;
34 }
35
41 public function getMultiSrtUploadDir()
42 {
43 return $this->multi_srt->getUploadDir();
44 }
45
46
53 public function uploadMultipleSubtitleFile($a_file)
54 {
55 include_once("./Services/MediaObjects/exceptions/class.ilMobSrtUploadException.php");
56 if (!is_file($a_file["tmp_name"])) {
57 throw new ilMobSrtUploadException($this->lng->txt("cont_srt_zip_file_could_not_be_uploaded"));
58 }
59
60 $dir = $this->getMultiSrtUploadDir();
61 ilUtil::delDir($dir, true);
63 ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir . "/" . "multi_srt.zip");
64 ilUtil::unzip($dir . "/multi_srt.zip", true);
65 }
66
70 public function clearMultiSrtDirectory()
71 {
73 }
74
78 public function getMultiSrtFiles()
79 {
80 $items = array();
81
82 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
84
85 $dir = $this->getMultiSrtUploadDir();
86 $files = ilUtil::getDir($dir);
87 foreach ($files as $k => $i) {
88 // check directory
89 if ($i["type"] == "file" && !in_array($k, array(".", ".."))) {
90 if (pathinfo($k, PATHINFO_EXTENSION) == "srt") {
91 $lang = "";
92 if (substr($k, strlen($k) - 7, 1) == "_") {
93 $lang = substr($k, strlen($k) - 6, 2);
94 if (!in_array($lang, $lang_codes)) {
95 $lang = "";
96 }
97 }
98 $items[] = array("filename" => $k, "lang" => $lang);
99 }
100 }
101 }
102
103 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
104 foreach ($this->multi_srt->getMobIds() as $mob) {
105 $m = new ilObjMediaObject($mob);
106 $mi = $m->getMediaItem("Standard");
107 if ($mi->getLocationType() == "LocalFile" && is_int(strpos($mi->getFormat(), "video"))) {
108 // $loc is e.g. "echo-hereweare.mp4", we not look for
109 // "echo-hereweare_<langcode>.srt" files
110 $loc = pathinfo($mi->getLocation(), PATHINFO_FILENAME);
111 foreach ($items as $i => $item) {
112 if (substr($item["filename"], 0, strlen($loc)) == $loc &&
113 substr($item["filename"], strlen($loc), 1) == "_" &&
114 pathinfo($item["filename"], PATHINFO_EXTENSION) == "srt") {
115 $l = substr($item["filename"], strlen($loc)+1, 2);
116 if (in_array($l, $lang_codes)) {
117 $items[$i]["lang"] = $l;
118 $items[$i]["mob"] = $mob;
119 $items[$i]["mob_title"] = $m->getTitle();
120 }
121 }
122 }
123 }
124 }
125
126 return $items;
127 }
128
132 public function moveMultiSrtFiles()
133 {
134 $items = $this->getMultiSrtFiles();
135 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
136 $cnt = 0;
137 foreach ($items as $i) {
138 if ($i["mob"] > 0 && $i["lang"] != "") {
139 $mob = new ilObjMediaObject($i["mob"]);
140 $mob->uploadSrtFile($this->getMultiSrtUploadDir() . "/" . $i["filename"], $i["lang"], "rename");
141 $cnt++;
142 }
143 }
144 return $cnt;
145 }
146}
$files
Definition: add-vimline.php:18
global $l
Definition: afr.php:30
An exception for terminatinating execution or to throw for unit testing.
Handler class for multi srt upload.
uploadMultipleSubtitleFile($a_file)
Upload multi srt file.
getMultiSrtUploadDir()
Get directory for multi srt upload.
clearMultiSrtDirectory()
Clear multi feedback directory.
__construct(ilMobMultiSrtInt $a_multi_srt)
Construcotr.
moveMultiSrtFiles()
Move all srt files that could be mapped to media objects.
getMultiSrtFiles()
Get all srt files of srt multi upload.
Exception class for srt upload.
Class ilObjMediaObject.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$lang
Definition: consent.php:3
$i
Definition: disco.tpl.php:19
Interface ilMobMultiSrtInt.
global $DIC
Definition: saml.php:7