changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / conversion_service / include / classes / ccformats / cc_MicroDvd_format.php
1 <?php\r
2 \r
3 /**\r
4  * MicroDvd Class\r
5  */\r
6 class MicroDvd extends CaptionFormat\r
7 {\r
8         private $textStyles = array();  \r
9         \r
10         /**\r
11          * Imports a caption string into a CaptionCollection \r
12          *\r
13          * @param String $theCCString the caption file as string\r
14          * @return CaptionCollection $myCcCollection A CaptionCollection Object\r
15          */\r
16         public function importCC($theCCString) {\r
17                 //global $ins, $caps, $outs, $num_clips,$proj_caption;\r
18                 $clips = array();\r
19                 $clip_string = '';\r
20             \r
21                 //$contents = file_get_contents($theCCFile);\r
22                 $contents = $theCCString;\r
23         \r
24         // clean malformed patterns creted when saving files on win notepad\r
25         $toSearch = array(chr(13).chr(10));\r
26         $toReplace = array(chr(10));\r
27         $contents = str_replace($toSearch,$toReplace,$contents);\r
28         \r
29         // Defining QText known pattenrs;\r
30         $pattern_QT_time_format = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})\]";\r
31         $pattern_QT_time_format_magpie = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})\]";\r
32         \r
33         $num_clips = preg_match_all("/$pattern_QT_time_format/", $contents, $clips);\r
34         \r
35         // if caption file is not QT and comes from MapPie time format\r
36                 if ($num_clips == 0)\r
37                 {\r
38                     $num_clips = preg_match_all("/$pattern_QT_time_format_magpie/", $contents, $clips);\r
39                 }\r
40                     \r
41                 //$num_clips = $num_clips/2; // this is not needed\r
42                 \r
43                 // create a collection object\r
44                 include_once('CaptionCollection.php');\r
45                 $myQTextCollection = new CaptionCollection();\r
46                 \r
47                 \r
48                 // build data arrays looing through $clips QT format: 1) Split using QT time format, Find all times\r
49                 for ($i=0; $i<$num_clips; $i=$i+2) {            \r
50                         \r
51                 // 2) Find all content in between QT time START and END using /s flag to capture also break lines\r
52                 $match_this = '/\['.$clips[1][$i].'\]\n(.*)\n\['.$clips[1][$i+1].'\]\n/s';                      \r
53                 preg_match($match_this, $contents, $clip_bit);\r
54                 \r
55                 // add captions to the collection\r
56                 $myQTextCollection->addCaptions($clips[1][$i],$clip_bit[1],$clips[1][$i+1]);\r
57                 \r
58                 /*\r
59                 $ins[] = $clips[1][$i];\r
60                 $caps[] = $clip_bit[1];\r
61                 $outs[] = $clips[1][$i+1];\r
62                                 */\r
63 \r
64                 } // end for \r
65         \r
66                 return $myQTextCollection;\r
67                  \r
68         } // end importCC()\r
69 \r
70         /**\r
71          * Exports a CaptionCollection object into a string\r
72          *\r
73          * @param CaptionCollection $theCollection A CaptionCollection Object\r
74          * @return String $captionString The caption as a String\r
75          */\r
76         public function exportCC($theCollection)\r
77         {\r
78                 \r
79                 $ccExport = '';\r
80         \r
81                 $myCollection = $theCollection->getCollection();\r
82                 \r
83                 foreach ($myCollection as $captionObj)\r
84                 {\r
85                         \r
86                         $miliSecIN = TimeUtil::timeQtToSami($captionObj->getInTime());\r
87                         $miliSecOUT = TimeUtil::timeQtToSami($captionObj->getOutTime());\r
88                         $fixCap = TxtFileTools::ccNewLineToBr($captionObj->getCaption(),' ');\r
89                         \r
90                         $ccExport .= "{".$miliSecIN."}{".$miliSecOUT."}".$fixCap."\n";\r
91                         \r
92                 } // end foreach\r
93                 \r
94                 return $ccExport;\r
95                 \r
96         } // end  exportCC()\r
97         \r
98         /**\r
99          * Verify if the caption file is a QText caption file \r
100         */\r
101         public function checkFormat($theCCString)\r
102         {\r
103                 $isValid = false;\r
104                 $patternCheck = "/({(QTtext)})/"; // RegExp to look for QText \r
105                 preg_match_all($patternCheck,$theCCString,$patternFound);\r
106                 \r
107                 if(count($patternFound)>0)\r
108                 {\r
109                         $isValid = true;\r
110                 }\r
111 \r
112                 return $isValid;\r
113                 \r
114         } // end  checkFormat() \r
115 \r
116         /*\r
117          * Here functions to re-define\r
118          */\r
119         public function getName()\r
120         {\r
121                 return 'MicroDvd';\r
122         }\r
123         \r
124         public function getAbout()\r
125         {\r
126                 return 'Caption Format used by the popular video player MicroDVD';\r
127         }\r
128         \r
129         public function getVersion()\r
130         {\r
131                 return '???';\r
132         }\r
133                 \r
134         public function getFileExtension()\r
135         {\r
136                 return 'sub';\r
137         }\r
138         \r
139         public function getIdPattern()\r
140         {\r
141                 $idPattern = '/unknown/';\r
142                 //\r
143                 return $idPattern;\r
144         }\r
145 \r
146         public function allowsTextStyles()\r
147         {\r
148                 return '0';\r
149         }\r
150         \r
151         public function template()\r
152         {\r
153                 $ccTemplate = '\r
154 {4952}{6082}caption 1\r
155 {6084}{8977}caption 2\r
156 {8979}{11928}caption 3\r
157 {11930}{13795}caption 4\r
158 {13797}{16569}caption 5\r
159 {16571}{17816}caption 6\r
160 {19656}{21412}caption 7\r
161 {21414}{23133}caption 8\r
162 {23135}{26100}caption 9\r
163 {26102}{28141}caption 10\r
164 {28143}{29867}caption 11\r
165 ';\r
166                 \r
167                 return $ccTemplate;\r
168         }\r
169         \r
170 }  // end MicroDvd class \r
171 ?>