changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / conversion_service / include / classes / ccformats / cc_QTSMIL_format.php
1 <?php\r
2 /**\r
3  * QTSMIL Class\r
4  */\r
5 class QTSMIL extends CaptionFormat\r
6 {\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                 } // end foreach\r
87                 \r
88         } // end  exportCC()\r
89         \r
90         /**\r
91          * Verify if the caption file is a QText caption file \r
92         */\r
93         public function checkFormat($theCCString)\r
94         {\r
95                 $isValid = false;\r
96                 $patternCheck = "/({(QTtext)})/"; // RegExp to look for QText \r
97                 preg_match_all($patternCheck,$theCCString,$patternFound);\r
98                 \r
99                 if(count($patternFound)>0)\r
100                 {\r
101                         $isValid = true;\r
102                 }\r
103 \r
104                 return $isValid;\r
105                 \r
106         } // end  checkFormat() \r
107 \r
108         /*\r
109          * Here functions to re-define\r
110          */\r
111         public function getName()\r
112         {\r
113                 return '';\r
114         }\r
115         \r
116         public function getAbout()\r
117         {\r
118                 return '';\r
119         }\r
120         \r
121         public function getVersion()\r
122         {\r
123                 return '';\r
124         }\r
125                 \r
126         public function getFileExtension()\r
127         {\r
128                 return '';\r
129         }\r
130         \r
131         public function getIdPattern()\r
132         {\r
133                 $idPattern = '/unknown/';\r
134                 //\r
135                 return $idPattern;\r
136         }\r
137 \r
138         public function allowsTextStyles()\r
139         {\r
140                 return '1';\r
141         }\r
142         public function template()\r
143         {\r
144                 $ccTemplate = '';\r
145                 \r
146                 return $ccTemplate;\r
147         }       \r
148 \r
149 }  // end classQText \r
150 ?>