1 : <?php
2 : /**
3 : * Roman de Renart
4 : *
5 : * PHP version 5
6 : *
7 : * @category Rdr
8 : * @package Edit
9 : * @author Michel Corne <mcorne@yahoo.com>
10 : * @copyright 2010 Michel Corne
11 : * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 : * @link http://roman-de-renart.blogspot.com/
13 : * @version SVN: $Id$
14 : */
15 :
16 : require_once 'Worksheet.php';
17 : require_once 'TableContents.php';
18 :
19 : /**
20 : * Episode settings and selection
21 : *
22 : * @category Rdr
23 : * @package Edit
24 : * @author Michel Corne <mcorne@yahoo.com>
25 : * @copyright 2010 Michel Corne
26 : * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
27 : */
28 :
29 : class Episode extends Worksheet
30 : {
31 : /**
32 : * The column numbers
33 : */
34 : const COL_MEON_NUMBERS = 0;
35 : const COL_MEON_TEXT_ORIG = 1;
36 : const COL_MEON_TEXT_CLEAN = 2;
37 : const COL_MEON_TEXT_FIXED = 3;
38 : const COL_MARTIN_CHAPTERS = 4;
39 : const COL_MARTIN_NUMBERS = 5;
40 : const COL_MARTIN_TEXT_ORIG = 6;
41 : const COL_FRO_NUMBERS = 7;
42 : const COL_FRO_TEXT = 8;
43 : const COL_DIFFERENCES = 9;
44 : const COL_TRANSLATION = 10;
45 : const COL_QUESTIONS_FRO = 11;
46 : const COL_QUESTIONS_TRANS = 12;
47 : const COL_QUESTIONS_TEXT = 13;
48 : const COL_MAPPING = 14;
49 :
50 : /**
51 : * The error message reported when there is no episode selected
52 : */
53 : const ERR_NO_EPISODE_SELECTED = 'you need to select an episode, use option -l to list the episodes.';
54 :
55 : /**
56 : * The format of the name of the HTML input file
57 : */
58 : const INPUT_FILE_FMT = '%s-in.html';
59 :
60 : /**
61 : * The message reported when an episode is selected
62 : */
63 : const MSG_EPISODE_SELECTED = "Episode selected:\n\n%s";
64 :
65 : /**
66 : * The format of the name of HTML output file
67 : */
68 : const OUTPUT_FILE_FMT = '%s-out.html';
69 :
70 : /**
71 : * The name of the file storing the selected episode details
72 : */
73 : const SELECTED_EPISODE_FILE = 'selected-episode.php';
74 :
75 : /**
76 : * The format of the name of the PHP working file
77 : */
78 : const WORKING_FILE_FMT = '%s.php';
79 :
80 : /**
81 : * The format of the name of the worksheet file
82 : */
83 : const WORKSHEET_FILE_FMT = '%s.csv';
84 :
85 : /**
86 : * The template of the container of the episode
87 : */
88 : const CONTAINER_TPL =
89 : '
90 : <!-- BEGIN EPISODE -->
91 : %s
92 : <!-- END EPISODE -->
93 : ';
94 :
95 : /**
96 : * The template of the episode
97 : */
98 : const EPISODE_TPL =
99 : '
100 : <div class="rdr-links">
101 : %s
102 : </div>
103 :
104 : <table class="rdr">
105 : <tbody>
106 :
107 : <tr class="rdr-top">
108 :
109 : <td class="rdr-left">
110 : <a href="%s">
111 : <img src="%s" />
112 : </a>
113 : %s
114 : </td>
115 :
116 : <td>
117 : </td>
118 :
119 : <td class="notranslate">
120 : <a href="http://www.ac-orleans-tours.fr/lettres/pedag/chev-lion/livre17.htm">
121 : <img src="%s" />
122 : </a>
123 : %s
124 : </td>
125 :
126 : </tr>
127 :
128 : <tr>
129 :
130 : <td>
131 : %s
132 : </td>
133 :
134 : <td class="rdr-number">
135 : %s
136 : </td>
137 :
138 : <td class="notranslate">
139 : %s
140 : </td>
141 :
142 : </tr>
143 :
144 : <tr class="rdr-title">
145 :
146 : <td>%s</td>
147 : <td></td>
148 : <td class="notranslate">%s</td>
149 :
150 : </tr>
151 :
152 : </tbody>
153 : </table>
154 :
155 : <div class="rdr-notes-link">
156 : <a href="javascript: displayORhideElt(\'rdr-notes-%s\')">Notes sur la traduction et l\'édition</a>
157 : </div>
158 :
159 : <div class="rdr-notes-section" id="rdr-notes-%s" style="display: none;">
160 :
161 : <div class="notranslate">
162 : <div class="rdr-notes-title">Traduction à confirmer</div>
163 :
164 : <div class="rdr-comments">
165 : Tout commentaire pour améliorer la traduction est bienvenu,
166 : en particulier pour traiter les points suivants. Merci !
167 : </div>
168 : <ul>
169 : %s
170 : </ul>
171 :
172 : <div class="rdr-notes-title">Leçons retenues de Méon et correspondance avec Martin et FHS</div>
173 : <ul>
174 : %s
175 : </ul>
176 :
177 : <div class="rdr-notes-title">Corrections des leçons de Méon avec FHS et Martin</div>
178 : <ul>
179 : %s
180 : </ul>
181 :
182 : </div>
183 :
184 : <a href="%s" target="rdrmeon">Texte original de Méon</a>
185 : <br />
186 : <a href="%s" target="rdrmartin">Texte original de Martin</a>
187 :
188 : </div>
189 :
190 : <div style="display: none;">
191 : %s
192 : </div>
193 :
194 : <div style="display: none;">
195 : %s
196 : </div>
197 :
198 : <div style="display: none;">
199 : %s
200 : </div>
201 :
202 : <div style="display: none;">
203 : %s
204 : </div>
205 :
206 : <div style="display: none;">
207 : %s
208 : </div>
209 :
210 : <div style="display: none;">
211 : %s
212 : </div>
213 :
214 : <div class="rdr-links">
215 : %s
216 : </div>
217 : ';
218 :
219 : /**
220 : * The template of the episode links
221 : */
222 : const LINKS_TPL =
223 : '
224 : <a href="http://roman-de-renart.blogspot.com/%s" title="Histoire précédente">%s</a>
225 : |
226 : <a href="http://roman-de-renart.blogspot.com/%s" title="Épisode précédent">Précédent</a>
227 : |
228 : <a href="http://roman-de-renart.blogspot.com/%s" title="Début de l\'histoire">%s</a>
229 : |
230 : <a href="http://roman-de-renart.blogspot.com/%s" title="Épisode suivant">Suivant</a>
231 : |
232 : <a href="http://roman-de-renart.blogspot.com/%s" title="Histoire suivante">%s</a>
233 : ';
234 :
235 : /**
236 : * The template of an episode list item
237 : */
238 : const LIST_TPL = '<li>%s</li>';
239 :
240 : /**
241 : * The text line separator
242 : */
243 : const LINE_SEPARATOR = '<br />';
244 :
245 : /**
246 : * The column headers
247 : * @var array
248 : */
249 : protected $columnHeaders = array(
250 : self::COL_MEON_NUMBERS => '#',
251 : self::COL_MEON_TEXT_ORIG => 'Méon original',
252 : self::COL_MEON_TEXT_CLEAN => 'Méon nettoyé',
253 : self::COL_MEON_TEXT_FIXED => 'Méon corrigé',
254 : self::COL_MARTIN_CHAPTERS => 'C',
255 : self::COL_MARTIN_NUMBERS => '#',
256 : self::COL_MARTIN_TEXT_ORIG => 'Martin original',
257 : self::COL_FRO_NUMBERS => '#',
258 : self::COL_FRO_TEXT => 'Ancien français',
259 : self::COL_DIFFERENCES => 'Différences',
260 : self::COL_TRANSLATION => 'Traduction',
261 : self::COL_QUESTIONS_FRO => 'Mot orig.',
262 : self::COL_QUESTIONS_TRANS => 'Mot trad.',
263 : self::COL_QUESTIONS_TEXT => 'Questions',
264 : self::COL_MAPPING => 'Correspondances',
265 : );
266 :
267 : /**
268 : * The columns name to number mapping
269 : * @var array
270 : */
271 : protected $columnNamesToNumbers = array(
272 : 'trans-text' => self::COL_TRANSLATION,
273 : 'fro-text' => self::COL_FRO_TEXT,
274 : 'questions' => self::COL_QUESTIONS_TEXT,
275 : 'mapping' => self::COL_MAPPING,
276 : 'differences' => self::COL_DIFFERENCES,
277 : 'meon-numbers' => self::COL_MEON_NUMBERS,
278 : 'meon-text' => self::COL_MEON_TEXT_ORIG,
279 : 'martin-chapters' => self::COL_MARTIN_CHAPTERS,
280 : 'martin-numbers' => self::COL_MARTIN_NUMBERS,
281 : 'martin-text' => self::COL_MARTIN_TEXT_ORIG,
282 : 'fro-numbers' => self::COL_FRO_NUMBERS,
283 : );
284 :
285 : /**
286 : * The episode content
287 : * @var array
288 : */
289 : public $episode;
290 :
291 : /**
292 : * The episode default settings
293 : * @var array
294 : */
295 : public $episodeDefault = array(
296 : 'links-top' => array(),
297 : 'img-url' => 'http://picasaweb.google.com/lh/photo/ei2R58YpwqJaUOQJc4RbTA?feat=directlink',
298 : 'img-src' => 'http://lh3.ggpht.com/_N-YOXCVv408/SoUkxGZ5YOI/AAAAAAAABgM/sUtwwDYoOdg/s288/99a-construction.jpg',
299 : 'trans-first-line' => array('breaks' => array ('', '', ''), 'text' => ''),
300 : 'letter-src' => '',
301 : 'fro-first-line' => array('breaks' => array ('', '', ''), 'text' => ''),
302 : 'trans-text' => array(),
303 : 'blog-numbers' => array(),
304 : 'fro-text' => array(),
305 : 'trans-unit-title' => 'TITRE UNITE (FR)',
306 : 'fro-unit-title' => 'TITRE UNITE (FRO)',
307 : 'notes-id0' => '',
308 : 'notes-id1' => '',
309 : 'questions' => array(),
310 : 'mapping' => array(),
311 : 'differences' => array(),
312 : 'meon-pdf' => '',
313 : 'martin-pdf' => '',
314 : 'meon-numbers' => array(),
315 : 'meon-text' => array(),
316 : 'martin-chapters' => array(),
317 : 'martin-numbers' => array(),
318 : 'martin-text' => array(),
319 : 'fro-numbers' => array(),
320 : 'links-bottom' => array(),
321 : );
322 :
323 : /**
324 : * The name of the HTML input file
325 : * @var string
326 : */
327 : public $inputFile;
328 :
329 : /**
330 : * The episode links default settings
331 : * @var array
332 : */
333 : public $linksDefault = array(
334 : 'prev-story-url' => '',
335 : 'prev-story-title' => 'HISTOIRE PRECEDENTE',
336 : 'prev-episode-url' => '',
337 : 'curr-story-url' => '',
338 : 'curr-story-title' => 'HISTOIRE COURANTE',
339 : 'next-episode-url' => 'http://roman-de-renart.blogspot.com/2009/02/prologue-le-livre.html',
340 : 'next-story-url' => 'http://roman-de-renart.blogspot.com/2009/02/prologue-le-livre.html',
341 : 'next-story-title' => 'Prologue',
342 : );
343 :
344 : /**
345 : * The details of a new episode
346 : * @var array
347 : */
348 : public $newEpisode = array (
349 : 'path' => 'new-episode.html',
350 : 'title' => 'Nouvel épisode',
351 : 'id' => '',
352 : );
353 :
354 : /**
355 : * The name of the HTML output file
356 : * @var string
357 : */
358 : public $outputFile;
359 :
360 : /**
361 : * The name of the file storing the selected episode details
362 : * @var string
363 : */
364 : public $selectedFile;
365 :
366 : /**
367 : * The name of the PHP working file
368 : * @var string
369 : */
370 : public $workingFile;
371 :
372 : /**
373 : * The name of the worksheet file
374 : * @var string
375 : */
376 : public $worksheetFile;
377 :
378 : /**
379 : * Constructor
380 : *
381 : * @param array $config the configuration directives
382 : * @param boolean $setFileNames sets the names of the working files if true, no setting if false
383 : * @param boolean $setSelectedFileName sets the name of the selected episode file if true, no setting if false
384 : * @return void
385 : */
386 : public function __construct($config, $setFileNames = true, $setSelectedFileName = true)
387 : {
388 51 : parent::__construct($config);
389 :
390 51 : $setSelectedFileName and $this->setSelectedFileName();
391 51 : $setFileNames and $this->setFileNames();
392 :
393 51 : }
394 :
395 : /**
396 : * Gets the details of the selected episode
397 : *
398 : * @return string the details of the episode
399 : */
400 : public function get()
401 : {
402 50 : return sprintf(self::MSG_EPISODE_SELECTED, $this->arrayToString($this->episode, true));
403 : }
404 :
405 : /**
406 : * Selects an episode for editing
407 : *
408 : * @param string $episodeID the episode identifier, defaults to the last episode if empty
409 : * @return string the details of the episode
410 : */
411 : public function select($episodeID = null)
412 : {
413 49 : if ($episodeID) {
414 : // finds the episode details from the table of contents
415 3 : $tableContents = new TableContents($this->config);
416 3 : $this->episode = $tableContents->findEpisodeById($episodeID);
417 3 : } else {
418 : // selects a new episode
419 49 : $this->episode = $this->newEpisode;
420 : }
421 : // stores those details
422 49 : $this->writeFile($this->selectedFile, $this->episode, true);
423 :
424 49 : return $this->get();
425 : }
426 :
427 : /**
428 : * Sets the names of the working files
429 : *
430 : * @return void
431 : */
432 : public function setFileNames()
433 : {
434 : // gets the details of the selected episode
435 50 : $this->fileExists($this->selectedFile, self::ERR_NO_EPISODE_SELECTED);
436 50 : $this->episode = $this->includeFile($this->selectedFile);
437 : // extracts the basename of the episode path
438 50 : $basename = basename($this->episode['path'], '.html');
439 :
440 : // sets the working files with the basename
441 50 : $this->inputFile = $this->makeFilePath($basename, 'wip-dir', self::INPUT_FILE_FMT);
442 50 : $this->outputFile = $this->makeFilePath($basename, 'wip-dir', self::OUTPUT_FILE_FMT);
443 50 : $this->workingFile = $this->makeFilePath($basename, 'wip-dir', self::WORKING_FILE_FMT);
444 50 : $this->worksheetFile = $this->makeFilePath($basename, 'wip-dir', self::WORKSHEET_FILE_FMT);
445 50 : }
446 :
447 : /**
448 : * Sets the name the selected episode file
449 : *
450 : * @return void
451 : */
452 : public function setSelectedFileName()
453 : {
454 51 : $this->selectedFile = $this->makeFilePath(self::SELECTED_EPISODE_FILE, 'wip-dir');
455 51 : }
|