5 class SubRipSrt extends CaptionFormat
\r
7 private $textStyles = array();
\r
10 * Imports a caption string into a CaptionCollection
\r
12 * @param String $theCCString the caption file as string
\r
13 * @return CaptionCollection $myCcCollection A CaptionCollection Object
\r
15 public function importCC($theCCString)
\r
19 // clean malformed patterns creted when saving files on win notepad
\r
20 $toSearch = array(chr(13).chr(10));
\r
21 $toReplace = array(chr(10));
\r
22 $theCCString = str_replace($toSearch,$toReplace,$theCCString);
\r
24 // split each caption by \n\n
\r
25 $allCaptions=split(chr(10).chr(10),$theCCString);
\r
27 // create a collection object
\r
28 $myCollection = new CaptionCollection();
\r
30 $txtStyles = Array();
\r
34 foreach($allCaptions as $singleCaption)
\r
37 //echo '<br/>'.chr(10).''.$counter;
\r
39 // split each line of the single caption
\r
40 $captionParts=split(chr(10),$singleCaption);
\r
42 // add captions if minimal time and caption are set
\r
43 if (isset($captionParts[1]) && isset($captionParts[2]))
\r
49 // fix milisecond separator "," by "."
\r
50 $captionParts[1] = str_replace(',','.',$captionParts[1]);
\r
52 // get time marks on line 2
\r
53 $timeMark = split('-->',$captionParts[1]);
\r
55 // get time in and out
\r
56 $timeIn = trim($timeMark[0]);
\r
57 $timeOut = trim($timeMark[1]);
\r
59 $captionLines = $captionParts[2]; // add caption line 1
\r
61 // if caption has two lines
\r
62 if (count($captionParts)==4)
\r
64 $captionLines .= ''.chr(10).$captionParts[3]; // add a new line + caption line 2
\r
67 // Create a caption Object
\r
68 $theNewCaption = new Caption($timeIn,$timeOut,$captionLines,$txtStyles);
\r
70 // add caption to CaptionCollection
\r
71 $myCollection->addCaption($theNewCaption);
\r
74 //echo ''.chr(10).'IN: '.$timeIn.'****'.' OUT:'.$timeOut;
\r
75 //echo ''.chr(10).''.$captionLines;
\r
80 return $myCollection;
\r
85 * Exports a CaptionCollection object into a string
\r
87 * @param CaptionCollection $theCollection A CaptionCollection Object
\r
88 * @return String $captionString The caption as a String
\r
90 public function exportCC($theCollection)
\r
95 $myCollection = $theCollection->getCollection();
\r
97 // fix time Srt Time Format
\r
98 $toSearch = array('.');
\r
99 $toReplace = array(',');
\r
103 foreach ($myCollection as $captionObj)
\r
108 // fix QT time to SRT format, replace "." by ","
\r
109 $srtInTime = $captionObj->getInTime();
\r
110 $srtInTime = str_replace($toSearch,$toReplace,$srtInTime);
\r
112 $srtOutTime = $captionObj->getOutTime();
\r
113 $srtOutTime = str_replace($toSearch,$toReplace,$srtOutTime);
\r
115 $srtCaption = $captionObj->getCaption();
\r
116 $srtCaption = str_replace('<BR/>',chr(10),$srtCaption);
\r
117 $srtCaption = str_replace('<br/>',chr(10),$srtCaption);
\r
119 $ccExport .= "$srtCounter\n".$srtInTime." --> ".$srtOutTime."\n".$srtCaption."\n\n";
\r
123 // Fix if there are more than the two empty line separator (standard)
\r
124 $ccExport = str_replace(chr(10).chr(10).chr(10),chr(10).chr(10),$ccExport);
\r
128 } // end exportCC()
\r
131 * Verify if the caption file is a QText caption file
\r
133 public function checkFormat($theCCString)
\r
136 $patternCheck = "/({(QTtext)})/"; // RegExp to look for QText
\r
137 preg_match_all($patternCheck,$theCCString,$patternFound);
\r
139 if(count($patternFound)>0)
\r
146 } // end checkFormat()
\r
149 * Here functions to re-define
\r
151 public function getName()
\r
153 return 'SubRip - Srt';
\r
156 public function getAbout()
\r
161 public function getVersion()
\r
166 public function getFileExtension()
\r
171 public function getIdPattern()
\r
173 $idPattern = '/([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}) (-->) ([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3})/';
\r
174 //$idPattern = '/([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3})/';
\r
176 //$idPattern .= '/'; // start pattern
\r
178 //$idPattern .= '([0-9]{2}\n)';
\r
180 //$idPattern .= '/'; // end pattern
\r
185 public function allowsTextStyles()
\r
190 public function template()
\r
194 00:00:42,360 --> 00:00:48,360
\r
195 With this device we can
\r
196 give anything an attitude.
\r
201 return $ccTemplate;
\r
203 } // end SubRipSrt
\r