ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCOPageHTMLExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13 private $mobs = array();
14 private $files = array();
15 private $files_direct = array();
16 private $exp_dir = "";
17 private $content_style_id = 0;
18
22 protected $log;
23
27 function __construct($a_exp_dir)
28 {
29
30 $this->log = ilLoggerFactory::getLogger('copg');
31
32 $this->exp_dir = $a_exp_dir;
33 $this->mobs_dir = $a_exp_dir."/mobs";
34 $this->files_dir = $a_exp_dir."/files";
35 $this->tex_dir = $a_exp_dir."/teximg";
36 $this->content_style_dir = $a_exp_dir."/content_style";
37 $this->content_style_img_dir = $a_exp_dir."/content_style/images";
38
39 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
40 $this->services_dir = $a_exp_dir."/Services";
41 $this->media_service_dir = $this->services_dir."/MediaObjects";
42 $this->flv_dir = $a_exp_dir."/".ilPlayerUtil::getFlashVideoPlayerDirectory();
43 $this->mp3_dir = $this->media_service_dir."/flash_mp3_player";
44
45 $this->js_dir = $a_exp_dir.'/js';
46 $this->js_yahoo_dir = $a_exp_dir.'/js/yahoo';
47 $this->css_dir = $a_exp_dir.'/css';
48
49 $GLOBALS["teximgcnt"] = 0;
50 }
51
57 function setContentStyleId($a_val)
58 {
59 $this->content_style_id = $a_val;
60 }
61
68 {
70 }
71
79 {
80 ilUtil::makeDir($this->mobs_dir);
81 ilUtil::makeDir($this->files_dir);
82 ilUtil::makeDir($this->tex_dir);
83 ilUtil::makeDir($this->content_style_dir);
84 ilUtil::makeDir($this->content_style_img_dir);
85 ilUtil::makeDir($this->services_dir);
86 ilUtil::makeDir($this->media_service_dir);
87 ilUtil::makeDir($this->flv_dir);
88 ilUtil::makeDir($this->mp3_dir);
89
90 ilUtil::makeDir($this->js_dir);
91 ilUtil::makeDir($this->js_yahoo_dir);
92 ilUtil::makeDir($this->css_dir);
93 }
94
101 function exportStyles()
102 {
103
104 $this->log->debug("export styles");
105
106 include_once "Services/Style/Content/classes/class.ilObjStyleSheet.php";
107
108 // export content style sheet
109 if ($this->getContentStyleId() < 1)
110 {
111 $cont_stylesheet = "./Services/COPage/css/content.css";
112
113 $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
114 preg_match_all("/url\‍(([^\‍)]*)\‍)/",$css,$files);
115 foreach (array_unique($files[1]) as $fileref)
116 {
117 if (is_file(str_replace("..", ".", $fileref)))
118 {
119 copy(str_replace("..", ".", $fileref), $this->content_style_img_dir."/".basename($fileref));
120 }
121 $css = str_replace($fileref, "images/".basename($fileref),$css);
122 }
123 fwrite(fopen($this->content_style_dir."/content.css",'w'),$css);
124 }
125 else
126 {
128 $style->writeCSSFile($this->content_style_dir."/content.css", "images");
129 $style->copyImagesToDir($this->content_style_img_dir);
130 }
131
132 // export syntax highlighting style
133 $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
134 copy($syn_stylesheet, $this->exp_dir."/syntaxhighlight.css");
135 }
136
146 {
147 $this->log->debug("export scripts");
148
149 // basic js
150 copy('./Services/JavaScript/js/Basic.js', $this->js_dir.'/Basic.js');
151
152 copy('./Services/UIComponent/Overlay/js/ilOverlay.js',$this->js_dir.'/ilOverlay.js');
153
154 // jquery
155 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
156 copy(iljQueryUtil::getLocaljQueryPath(), $this->js_dir.'/jquery.js');
157 copy(iljQueryUtil::getLocaljQueryUIPath(), $this->js_dir.'/jquery-ui-min.js');
158 copy(iljQueryUtil::getLocalMaphilightPath(), $this->js_dir.'/maphilight.js');
159
160 // yui stuff we use
161 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
162 copy(ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
163 $this->js_yahoo_dir.'/yahoo-min.js');
164 copy(ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
165 $this->js_yahoo_dir.'/yahoo-dom-event.js');
166 copy(ilYuiUtil::getLocalPath('animation/animation-min.js'),
167 $this->js_yahoo_dir.'/animation-min.js');
168 copy(ilYuiUtil::getLocalPath('container/container-min.js'),
169 $this->js_yahoo_dir.'/container-min.js');
170 copy(ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'),
171 $this->css_dir.'/container.css');
172
173 // accordion
174 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
176 {
177 $tfile = $this->exp_dir."/".$f;
178 ilUtil::makeDirParents(dirname($tfile));
179 copy($f, $tfile);
180 }
181 foreach (ilAccordionGUI::getLocalCssFiles() as $f)
182 {
183 $tfile = $this->exp_dir."/".$f;
184 ilUtil::makeDirParents(dirname($tfile));
185 copy($f, $tfile);
186 }
187
188 copy('./Services/Accordion/js/accordion.js',
189 $this->js_dir.'/accordion.js');
190 copy('./Services/Accordion/css/accordion.css',
191 $this->css_dir.'/accordion.css');
192
193 // page presentation js
194 copy('./Services/COPage/js/ilCOPagePres.js',
195 $this->js_dir.'/ilCOPagePres.js');
196
197 // tooltip
198 copy('./Services/UIComponent/Tooltip/js/ilTooltip.js',
199 $this->js_dir.'/ilTooltip.js');
200
201 // mediaelement.js
202 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
204
205 // matching / multiple choice - question
206 copy('./Modules/TestQuestionPool/js/ilMatchingQuestion.js',
207 $this->js_dir.'/ilMatchingQuestion.js');
208 copy('./Modules/TestQuestionPool/js/ilAssMultipleChoice.js',
209 $this->js_dir.'/ilAssMultipleChoice.js');
210 copy('./Modules/TestQuestionPool/templates/default/test_javascript.css',
211 $this->css_dir.'/test_javascript.css');
212
213 // auto linking js
214 include_once("./Services/Link/classes/class.ilLinkifyUtil.php");
215 foreach (ilLinkifyUtil::getLocalJsPaths() as $p)
216 {
217 if (is_int(strpos($p, "ExtLink")))
218 {
219 copy($p, $this->js_dir.'/ilExtLink.js');
220 }
221 if (is_int(strpos($p, "linkify")))
222 {
223 copy($p, $this->js_dir.'/linkify.js');
224 }
225 }
226
227
228// copy(ilPlayerUtil::getLocalMediaElementCssPath(),
229// $this->css_dir.'/mediaelementplayer.css');
230// copy(ilPlayerUtil::getLocalMediaElementJsPath(),
231// $this->js_dir.'/mediaelement-and-player.js');
232 }
233
240 function getPreparedMainTemplate($a_tpl = "")
241 {
242 global $ilUser;
243
244 $this->log->debug("get main template");
245
246 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
247
248 if ($a_tpl != "")
249 {
250 $tpl = $a_tpl;
251 }
252 else
253 {
254 // template workaround: reset of template
255 $tpl = new ilTemplate("tpl.main.html", true, true);
256 }
257
258 // scripts needed
259 $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
260 "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js", "./js/jquery.js",
261 "./js/Basic.js", "./js/jquery-ui-min.js",
262 "./js/ilOverlay.js", "./js/ilCOPagePres.js",
263 "./js/ilTooltip.js", "./js/maphilight.js", "./js/ilMatchingQuestion.js", "./js/ilAssMultipleChoice.js",
264 "./js/ilExtLink.js", "./js/linkify.js");
265 $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
266
267 $mathJaxSetting = new ilSetting("MathJax");
268 $use_mathjax = $mathJaxSetting->get("enable");
269 if ($use_mathjax)
270 {
271 $scripts[] = $mathJaxSetting->get("path_to_mathjax");
272 }
273
274 // accordion
275 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
277 {
278 $scripts[] = $f;
279 }
280
281 foreach ($scripts as $script)
282 {
283 $tpl->setCurrentBlock("js_file");
284 $tpl->setVariable("JS_FILE", $script);
285 $tpl->parseCurrentBlock();
286 }
287
288 // css files needed
289 $style_name = $ilUser->prefs["style"].".css";
290 $css_files = array("./css/container.css",
291 "./content_style/content.css", "./style/".$style_name, "./css/test_javascript.css");
292 $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
293
294 // accordion
295 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
296 foreach (ilAccordionGUI::getLocalCssFiles() as $f)
297 {
298 $css_files[] = $f;
299 }
300
301
302 foreach ($css_files as $css)
303 {
304 $tpl->setCurrentBlock("css_file");
305 $tpl->setVariable("CSS_FILE", $css);
306 $tpl->parseCurrentBlock();
307 }
308
309 return $tpl;
310 }
311
319 {
320 $this->log->debug("collect page elements");
321
322 // collect media objects
324 foreach($pg_mobs as $pg_mob)
325 {
326 $this->mobs[$pg_mob] = $pg_mob;
327 }
328
329 // collect all files
330 include_once("./Modules/File/classes/class.ilObjFile.php");
332 foreach($files as $f)
333 {
334 $this->files[$f] = $f;
335 }
336
337
338 $skill_tree = $ws_tree = null;
339
341 foreach ($pcs as $pc)
342 {
343 // skils
344 if ($pc["type"] == "skmg")
345 {
346 $skill_id = $pc["id"];
347
348 // trying to find user id
349 $user_id = null;
350 switch($a_type)
351 {
352 case "prtf:pg":
353 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
354 $page = new ilPortfolioPage($a_id);
355 $user_id = $page->create_user;
356 break;
357
358 default:
359 // :TODO:
360 break;
361 }
362
363 if($user_id)
364 {
365 // we only need 1 instance each
366 if(!$skill_tree)
367 {
368 include_once "Services/Skill/classes/class.ilSkillTree.php";
369 $skill_tree = new ilSkillTree();
370
371 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
372
373 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
374 $ws_tree = new ilWorkspaceTree($user_id);
375 }
376
377 // walk skill tree
378 include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
379 $vtree = new ilVirtualSkillTree();
380 $tref_id = 0;
381 $skill_id = (int) $skill_id;
382 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
383 if (ilSkillTreeNode::_lookupType($skill_id) == "sktr")
384 {
385 include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
386 $tref_id = $skill_id;
387 $skill_id = ilSkillTemplateReference::_lookupTemplateId($skill_id);
388 }
389 $b_skills = $vtree->getSubTreeForCSkillId($skill_id.":".$tref_id, true);
390
391 foreach ($b_skills as $bs)
392 {
393 $skill = ilSkillTreeNodeFactory::getInstance($bs["skill_id"]);
394 $level_data = $skill->getLevelData();
395 foreach ($level_data as $k => $v)
396 {
397 // get assigned materials from personal skill
398 $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref_id"], $v["id"]);
399 if(sizeof($mat))
400 {
401 foreach($mat as $item)
402 {
403 $wsp_id = $item["wsp_id"];
404 $obj_id = $ws_tree->lookupObjectId($wsp_id);
405
406 // all possible material types for now
407 switch(ilObject::_lookupType($obj_id))
408 {
409 case "file":
410 $this->files[$obj_id] = $obj_id;
411 break;
412
413 case "tstv":
414 include_once "Modules/Test/classes/class.ilObjTestVerification.php";
415 $obj = new ilObjTestVerification($obj_id, false);
416 $this->files_direct[$obj_id] = array($obj->getFilePath(),
417 $obj->getOfflineFilename());
418 break;
419
420 case "excv":
421 include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
422 $obj = new ilObjExerciseVerification($obj_id, false);
423 $this->files_direct[$obj_id] = array($obj->getFilePath(),
424 $obj->getOfflineFilename());
425 break;
426
427 case "crsv":
428 include_once "Modules/Course/classes/Verification/class.ilObjCourseVerification.php";
429 $obj = new ilObjCourseVerification($obj_id, false);
430 $this->files_direct[$obj_id] = array($obj->getFilePath(),
431 $obj->getOfflineFilename());
432 break;
433
434 case "scov":
435 include_once "Modules/ScormAicc/classes/Verification/class.ilObjSCORMVerification.php";
436 $obj = new ilObjSCORMVerification($obj_id, false);
437 $this->files_direct[$obj_id] = array($obj->getFilePath(),
438 $obj->getOfflineFilename());
439 break;
440 }
441 }
442 }
443 }
444 }
445 }
446 }
447 }
448
449 }
450
457 function exportPageElements($a_update_callback = null)
458 {
459 $this->log->debug("export page elements");
460
461 $total = count($this->mobs) + count($this->files) + count($this->files_direct);
462 $cnt = 0;
463
464 // export all media objects
465 $linked_mobs = array();
466 foreach ($this->mobs as $mob)
467 {
468 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
469 {
470 $this->exportHTMLMOB($mob, $linked_mobs);
471 }
472 if (is_callable($a_update_callback))
473 {
474 $cnt++;
475 $a_update_callback($total, $cnt);
476 }
477 }
478 $linked_mobs2 = array(); // mobs linked in link areas
479 foreach ($linked_mobs as $mob)
480 {
481 if (ilObject::_exists($mob))
482 {
483 $this->exportHTMLMOB($mob, $linked_mobs2);
484 }
485 }
486
487 // export all file objects
488 foreach ($this->files as $file)
489 {
490 $this->exportHTMLFile($file);
491 if (is_callable($a_update_callback))
492 {
493 $cnt++;
494 $a_update_callback($total, $cnt);
495 }
496 }
497
498 // export all files (which are not objects
499 foreach ($this->files_direct as $file_id => $attr)
500 {
501 $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
502 if (is_callable($a_update_callback))
503 {
504 $cnt++;
505 $a_update_callback($total, $cnt);
506 }
507 }
508 }
509
513 function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
514 {
515 global $tpl;
516
517 $this->log->debug("export html mobs");
518
519 $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
520 if (@is_dir($source_dir))
521 {
522 ilUtil::makeDir($this->mobs_dir."/mm_".$a_mob_id);
523 ilUtil::rCopy($source_dir, $this->mobs_dir."/mm_".$a_mob_id);
524 }
525
526 // #12930 - fullscreen
527 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
528 $mob_obj = new ilObjMediaObject($a_mob_id);
529 if ($mob_obj->hasFullscreenItem())
530 {
531 // render media object html
532 $xh = xslt_create();
533 $output = xslt_process(
534 $xh,
535 "arg:/_xml",
536 "arg:/_xsl",
537 NULL,
538 array(
539 "/_xml" =>
540 "<dummy>".
541 $mob_obj->getXML(IL_MODE_ALIAS).
542 $mob_obj->getXML(IL_MODE_OUTPUT).
543 "</dummy>",
544 "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
545 ),
546 array("mode"=>"fullscreen"));
547 xslt_free($xh);
548 unset($xh);
549
550 // render fullscreen html
551 $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
552 $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
553 $tpl->setCurrentBlock("ilMedia");
554 $tpl->setVariable("MEDIA_CONTENT", $output);
555 $output = $tpl->get();
556 unset($tpl);
557
558 // write file
559 $file = $this->exp_dir."/fullscreen_".$a_mob_id.".html";
560 if(!($fp = @fopen($file,"w+")))
561 {
562 die("<b>Error</b>: Could not open \"".$file."\" for writing".
563 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
564 }
565 chmod($file, 0770);
566 fwrite($fp, $output);
567 fclose($fp);
568 unset($fp);
569 unset($output);
570 }
571
572 $linked_mobs = $mob_obj->getLinkedMediaObjects();
573 $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
574 }
575
579 function exportHTMLFile($a_file_id)
580 {
581 $file_dir = $this->files_dir."/file_".$a_file_id;
582 ilUtil::makeDir($file_dir);
583
584 include_once("./Modules/File/classes/class.ilObjFile.php");
585 $file_obj = new ilObjFile($a_file_id, false);
586 $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
587 if (!is_file($source_file))
588 {
589 $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
590 }
591 if (is_file($source_file))
592 {
593 copy($source_file, $file_dir."/".$file_obj->getFileName());
594 }
595 }
596
600 function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
601 {
602 $file_dir = $this->files_dir."/file_".$a_file_id;
603 ilUtil::makeDir($file_dir);
604
605 if (is_file($a_source_file))
606 {
607 copy($a_source_file,
608 $file_dir."/".ilUtil::getASCIIFilename($a_file_name));
609 }
610 }
611
612}
613
614?>
global $tpl
Definition: ilias.php:8
if(strpos( $jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:36
$total
Definition: Utf8Test.php:87
An exception for terminatinating execution or to throw for unit testing.
const IL_MODE_ALIAS
const IL_MODE_OUTPUT
static getLocalJavascriptFiles()
HTML export class for pages.
exportHTMLFile($a_file_id)
Export file object.
__construct($a_exp_dir)
Initialisation.
getPreparedMainTemplate($a_tpl="")
Get prepared main template.
exportHTMLMOB($a_mob_id, &$a_linked_mobs)
Export media object to html.
createDirectories()
Create directories.
exportStyles()
Export content style.
exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
Export file from path.
exportSupportScripts()
Export support scripts.
setContentStyleId($a_val)
Set content style id.
collectPageElements($a_type, $a_id)
Collect page elements (that need to be exported separately)
getContentStyleId()
Get content style id.
exportPageElements($a_update_callback=null)
Export page elements.
static getLocalJsPaths()
Get paths of necessary js files.
static getLogger($a_component_id)
Get component logger.
Class ilObjFile.
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
Class ilObjMediaObject.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
Class ilObjStyleSheet.
static getSyntaxStylePath()
get syntax style path
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupType($a_id, $a_reference=false)
lookup object type
static getUsagesOfPage($a_usage_id, $a_usage_type, $a_hist_nr=0, $a_all_hist_nrs=false, $a_lang="-")
Get page content usages for page.
static getAssignedMaterial($a_user_id, $a_tref_id, $a_level)
Get assigned material (for a skill level and user)
static getFlashVideoPlayerDirectory()
Get flash video player directory.
static getJsFilePaths()
Get js file paths.
static getCssFilePaths()
Get css file paths.
static copyPlayerFilesToTargetDirectory($a_target_dir)
Copy css files to target dir.
Page for user portfolio.
ILIAS Setting Class.
static _lookupTemplateId($a_obj_id)
Lookup template ID.
static _lookupType($a_obj_id)
Lookup Type.
special template class to simplify handling of ITX/PEAR
static getWebspaceDir($mode="filesystem")
get webspace directory
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
Tree handler for personal workspace.
static getLocalPath($a_name="")
Get local path of a YUI js file.
static getLocaljQueryUIPath()
Get local path of jQuery UI file.
static getLocaljQueryPath()
Get local path of jQuery file.
static getLocalMaphilightPath()
Get local path of maphilight file.
$style
Definition: example_012.php:70
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
xslt_free(&$proc)
xslt_create()
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93