ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
16 protected $mobs = array();
17
21 protected $files = array();
22
26 protected $files_direct = array();
27
31 protected $exp_dir = "";
32
36 protected $content_style_id = 0;
37
41 protected $user;
42
46 protected $log;
47
52 public function __construct($a_exp_dir)
53 {
54 global $DIC;
55
56 $this->log = ilLoggerFactory::getLogger('copg');
57 $this->user = $DIC->user();
58
59 $this->exp_dir = $a_exp_dir;
60 $this->mobs_dir = $a_exp_dir . "/mobs";
61 $this->files_dir = $a_exp_dir . "/files";
62 $this->tex_dir = $a_exp_dir . "/teximg";
63 $this->content_style_dir = $a_exp_dir . "/content_style";
64 $this->content_style_img_dir = $a_exp_dir . "/content_style/images";
65
66 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
67 $this->services_dir = $a_exp_dir . "/Services";
68 $this->media_service_dir = $this->services_dir . "/MediaObjects";
69 $this->flv_dir = $a_exp_dir . "/" . ilPlayerUtil::getFlashVideoPlayerDirectory();
70 $this->mp3_dir = $this->media_service_dir . "/flash_mp3_player";
71
72 $this->js_dir = $a_exp_dir . '/js';
73 $this->js_yahoo_dir = $a_exp_dir . '/js/yahoo';
74 $this->css_dir = $a_exp_dir . '/css';
75 }
76
82 public function setContentStyleId($a_val)
83 {
84 $this->content_style_id = $a_val;
85 }
86
92 public function getContentStyleId()
93 {
95 }
96
103 public function createDirectories()
104 {
105 ilUtil::makeDir($this->mobs_dir);
106 ilUtil::makeDir($this->files_dir);
107 ilUtil::makeDir($this->tex_dir);
108 ilUtil::makeDir($this->content_style_dir);
109 ilUtil::makeDir($this->content_style_img_dir);
110 ilUtil::makeDir($this->services_dir);
111 ilUtil::makeDir($this->media_service_dir);
112 ilUtil::makeDir($this->flv_dir);
113 ilUtil::makeDir($this->mp3_dir);
114
115 ilUtil::makeDir($this->js_dir);
116 ilUtil::makeDir($this->js_yahoo_dir);
117 ilUtil::makeDir($this->css_dir);
118 ilUtil::makeDir($this->css_dir . "/yahoo");
119 }
120
127 public function exportStyles()
128 {
129 $this->log->debug("export styles");
130
131 include_once "Services/Style/Content/classes/class.ilObjStyleSheet.php";
132
133 // export content style sheet
134 if ($this->getContentStyleId() < 1) {
135 $cont_stylesheet = "./Services/COPage/css/content.css";
136
137 $css = fread(fopen($cont_stylesheet, 'r'), filesize($cont_stylesheet));
138 preg_match_all("/url\‍(([^\‍)]*)\‍)/", $css, $files);
139 foreach (array_unique($files[1]) as $fileref) {
140 if (is_file(str_replace("..", ".", $fileref))) {
141 copy(str_replace("..", ".", $fileref), $this->content_style_img_dir . "/" . basename($fileref));
142 }
143 $css = str_replace($fileref, "images/" . basename($fileref), $css);
144 }
145 fwrite(fopen($this->content_style_dir . "/content.css", 'w'), $css);
146 } else {
148 $style->writeCSSFile($this->content_style_dir . "/content.css", "images");
149 $style->copyImagesToDir($this->content_style_img_dir);
150 }
151
152 // export syntax highlighting style
153 $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
154 copy($syn_stylesheet, $this->exp_dir . "/syntaxhighlight.css");
155 }
156
165 public function exportSupportScripts()
166 {
167 $this->log->debug("export scripts");
168
169 // basic js
170 copy('./Services/JavaScript/js/Basic.js', $this->js_dir . '/Basic.js');
171
172 copy('./Services/UIComponent/Overlay/js/ilOverlay.js', $this->js_dir . '/ilOverlay.js');
173
174 // jquery
175 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
176 copy(iljQueryUtil::getLocaljQueryPath(), $this->js_dir . '/jquery.js');
177 copy(iljQueryUtil::getLocaljQueryUIPath(), $this->js_dir . '/jquery-ui-min.js');
178 copy(iljQueryUtil::getLocalMaphilightPath(), $this->js_dir . '/maphilight.js');
179
180 // yui stuff we use
181 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
182 copy(
183 ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
184 $this->js_yahoo_dir . '/yahoo-min.js'
185 );
186 copy(
187 ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
188 $this->js_yahoo_dir . '/yahoo-dom-event.js'
189 );
190 copy(
191 ilYuiUtil::getLocalPath('animation/animation-min.js'),
192 $this->js_yahoo_dir . '/animation-min.js'
193 );
194 copy(
195 ilYuiUtil::getLocalPath('container/container-min.js'),
196 $this->js_yahoo_dir . '/container-min.js'
197 );
198 copy(
199 ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'),
200 $this->css_dir . '/container.css'
201 );
202 copy(
203 ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'),
204 $this->css_dir . '/yahoo/container.css'
205 ); // see #23083
206
207 // accordion
208 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
210 $tfile = $this->exp_dir . "/" . $f;
211 ilUtil::makeDirParents(dirname($tfile));
212 copy($f, $tfile);
213 }
214 foreach (ilAccordionGUI::getLocalCssFiles() as $f) {
215 $tfile = $this->exp_dir . "/" . $f;
216 ilUtil::makeDirParents(dirname($tfile));
217 copy($f, $tfile);
218 }
219
220 copy(
221 './Services/Accordion/js/accordion.js',
222 $this->js_dir . '/accordion.js'
223 );
224 copy(
225 './Services/Accordion/css/accordion.css',
226 $this->css_dir . '/accordion.css'
227 );
228
229 // page presentation js
230 copy(
231 './Services/COPage/js/ilCOPagePres.js',
232 $this->js_dir . '/ilCOPagePres.js'
233 );
234
235 // tooltip
236 copy(
237 './Services/UIComponent/Tooltip/js/ilTooltip.js',
238 $this->js_dir . '/ilTooltip.js'
239 );
240
241 // mediaelement.js
242 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
244
245 // matching / multiple choice - question
246 copy(
247 './Modules/TestQuestionPool/js/ilMatchingQuestion.js',
248 $this->js_dir . '/ilMatchingQuestion.js'
249 );
250 copy(
251 './Modules/TestQuestionPool/js/ilAssMultipleChoice.js',
252 $this->js_dir . '/ilAssMultipleChoice.js'
253 );
254 copy(
255 './Modules/TestQuestionPool/templates/default/test_javascript.css',
256 $this->css_dir . '/test_javascript.css'
257 );
258
259 // auto linking js
260 include_once("./Services/Link/classes/class.ilLinkifyUtil.php");
261 foreach (ilLinkifyUtil::getLocalJsPaths() as $p) {
262 if (is_int(strpos($p, "ExtLink"))) {
263 copy($p, $this->js_dir . '/ilExtLink.js');
264 }
265 if (is_int(strpos($p, "linkify"))) {
266 copy($p, $this->js_dir . '/linkify.js');
267 }
268 }
269
270
271 // copy(ilPlayerUtil::getLocalMediaElementCssPath(),
272// $this->css_dir.'/mediaelementplayer.css');
273// copy(ilPlayerUtil::getLocalMediaElementJsPath(),
274// $this->js_dir.'/mediaelement-and-player.js');
275 }
276
283 public function getPreparedMainTemplate($a_tpl = "")
284 {
285 $this->log->debug("get main template");
286
287 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
288
289 if ($a_tpl != "") {
290 $tpl = $a_tpl;
291 } else {
292 // template workaround: reset of template
293 $tpl = new ilTemplate("tpl.main.html", true, true);
294 }
295
296 // scripts needed
297 $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
298 "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js", "./js/jquery.js",
299 "./js/Basic.js", "./js/jquery-ui-min.js",
300 "./js/ilOverlay.js", "./js/ilCOPagePres.js",
301 "./js/ilTooltip.js", "./js/maphilight.js", "./js/ilMatchingQuestion.js", "./js/ilAssMultipleChoice.js",
302 "./js/ilExtLink.js", "./js/linkify.js");
303 $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
304
305 $mathJaxSetting = new ilSetting("MathJax");
306 $use_mathjax = $mathJaxSetting->get("enable");
307 if ($use_mathjax) {
308 $scripts[] = $mathJaxSetting->get("path_to_mathjax");
309 }
310
311 // accordion
312 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
314 $scripts[] = $f;
315 }
316
317 foreach ($scripts as $script) {
318 $tpl->setCurrentBlock("js_file");
319 $tpl->setVariable("JS_FILE", $script);
320 $tpl->parseCurrentBlock();
321 }
322
323 // css files needed
324 $style_name = $this->user->prefs["style"] . ".css";
325 $css_files = array("./css/container.css",
326 "./content_style/content.css", "./style/" . $style_name, "./css/test_javascript.css");
327 $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
328
329 // accordion
330 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
331 foreach (ilAccordionGUI::getLocalCssFiles() as $f) {
332 $css_files[] = $f;
333 }
334
335
336 foreach ($css_files as $css) {
337 $tpl->setCurrentBlock("css_file");
338 $tpl->setVariable("CSS_FILE", $css);
339 $tpl->parseCurrentBlock();
340 }
341
342 return $tpl;
343 }
344
351 public function collectPageElements($a_type, $a_id)
352 {
353 $this->log->debug("collect page elements");
354
355 // collect media objects
357 foreach ($pg_mobs as $pg_mob) {
358 $this->mobs[$pg_mob] = $pg_mob;
359 }
360
361 // collect all files
362 include_once("./Modules/File/classes/class.ilObjFile.php");
364 foreach ($files as $f) {
365 $this->files[$f] = $f;
366 }
367
368
369 $skill_tree = $ws_tree = null;
370
372 foreach ($pcs as $pc) {
373 // skils
374 if ($pc["type"] == "skmg") {
375 $skill_id = $pc["id"];
376
377 // trying to find user id
378 $user_id = null;
379 switch ($a_type) {
380 case "prtf:pg":
381 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
382 $page = new ilPortfolioPage($a_id);
383 $user_id = $page->create_user;
384 break;
385
386 default:
387 // :TODO:
388 break;
389 }
390
391 if ($user_id) {
392 // we only need 1 instance each
393 if (!$skill_tree) {
394 include_once "Services/Skill/classes/class.ilSkillTree.php";
395 $skill_tree = new ilSkillTree();
396
397 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
398
399 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
400 $ws_tree = new ilWorkspaceTree($user_id);
401 }
402
403 // walk skill tree
404 include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
405 $vtree = new ilVirtualSkillTree();
406 $tref_id = 0;
407 $skill_id = (int) $skill_id;
408 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
409 if (ilSkillTreeNode::_lookupType($skill_id) == "sktr") {
410 include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
411 $tref_id = $skill_id;
412 $skill_id = ilSkillTemplateReference::_lookupTemplateId($skill_id);
413 }
414 $b_skills = $vtree->getSubTreeForCSkillId($skill_id . ":" . $tref_id, true);
415
416 foreach ($b_skills as $bs) {
417 $skill = ilSkillTreeNodeFactory::getInstance($bs["skill_id"]);
418 $level_data = $skill->getLevelData();
419 foreach ($level_data as $k => $v) {
420 // get assigned materials from personal skill
421 $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref_id"], $v["id"]);
422 if (sizeof($mat)) {
423 foreach ($mat as $item) {
424 $wsp_id = $item["wsp_id"];
425 $obj_id = $ws_tree->lookupObjectId($wsp_id);
426
427 // all possible material types for now
428 switch (ilObject::_lookupType($obj_id)) {
429 case "file":
430 $this->files[$obj_id] = $obj_id;
431 break;
432
433 case "tstv":
434 include_once "Modules/Test/classes/class.ilObjTestVerification.php";
435 $obj = new ilObjTestVerification($obj_id, false);
436 $this->files_direct[$obj_id] = array($obj->getFilePath(),
437 $obj->getOfflineFilename());
438 break;
439
440 case "excv":
441 include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
442 $obj = new ilObjExerciseVerification($obj_id, false);
443 $this->files_direct[$obj_id] = array($obj->getFilePath(),
444 $obj->getOfflineFilename());
445 break;
446
447 case "crsv":
448 include_once "Modules/Course/classes/Verification/class.ilObjCourseVerification.php";
449 $obj = new ilObjCourseVerification($obj_id, false);
450 $this->files_direct[$obj_id] = array($obj->getFilePath(),
451 $obj->getOfflineFilename());
452 break;
453
454 case "scov":
455 include_once "Modules/ScormAicc/classes/Verification/class.ilObjSCORMVerification.php";
456 $obj = new ilObjSCORMVerification($obj_id, false);
457 $this->files_direct[$obj_id] = array($obj->getFilePath(),
458 $obj->getOfflineFilename());
459 break;
460 }
461 }
462 }
463 }
464 }
465 }
466 }
467 }
468 }
469
476 public function exportPageElements($a_update_callback = null)
477 {
478 $this->log->debug("export page elements");
479
480 $total = count($this->mobs) + count($this->files) + count($this->files_direct);
481 $cnt = 0;
482
483 // export all media objects
484 $linked_mobs = array();
485 foreach ($this->mobs as $mob) {
486 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
487 $this->exportHTMLMOB($mob, $linked_mobs);
488 }
489 if (is_callable($a_update_callback)) {
490 $cnt++;
491 $a_update_callback($total, $cnt);
492 }
493 }
494 $linked_mobs2 = array(); // mobs linked in link areas
495 foreach ($linked_mobs as $mob) {
496 if (ilObject::_exists($mob)) {
497 $this->exportHTMLMOB($mob, $linked_mobs2);
498 }
499 }
500
501 // export all file objects
502 foreach ($this->files as $file) {
503 $this->exportHTMLFile($file);
504 if (is_callable($a_update_callback)) {
505 $cnt++;
506 $a_update_callback($total, $cnt);
507 }
508 }
509
510 // export all files (which are not objects
511 foreach ($this->files_direct as $file_id => $attr) {
512 $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
513 if (is_callable($a_update_callback)) {
514 $cnt++;
515 $a_update_callback($total, $cnt);
516 }
517 }
518 }
519
523 public function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
524 {
525 $this->log->debug("export html mobs");
526
527 $source_dir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $a_mob_id;
528 if (@is_dir($source_dir)) {
529 ilUtil::makeDir($this->mobs_dir . "/mm_" . $a_mob_id);
530 ilUtil::rCopy($source_dir, $this->mobs_dir . "/mm_" . $a_mob_id);
531 }
532
533 // #12930 - fullscreen
534 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
535 $mob_obj = new ilObjMediaObject($a_mob_id);
536 if ($mob_obj->hasFullscreenItem()) {
537 // render media object html
538 $xh = xslt_create();
539 $output = xslt_process(
540 $xh,
541 "arg:/_xml",
542 "arg:/_xsl",
543 null,
544 array(
545 "/_xml" =>
546 "<dummy>" .
547 $mob_obj->getXML(IL_MODE_ALIAS) .
548 $mob_obj->getXML(IL_MODE_OUTPUT) .
549 "</dummy>",
550 "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
551 ),
552 array("mode"=>"fullscreen")
553 );
554 xslt_free($xh);
555 unset($xh);
556
557 // render fullscreen html
558 $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
559 $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
560 $tpl->setCurrentBlock("ilMedia");
561 $tpl->setVariable("MEDIA_CONTENT", $output);
562 $output = $tpl->get();
563 unset($tpl);
564
565 // write file
566 $file = $this->exp_dir . "/fullscreen_" . $a_mob_id . ".html";
567 if (!($fp = @fopen($file, "w+"))) {
568 die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
569 " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
570 }
571 chmod($file, 0770);
572 fwrite($fp, $output);
573 fclose($fp);
574 unset($fp);
575 unset($output);
576 }
577
578 $linked_mobs = $mob_obj->getLinkedMediaObjects();
579 $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
580 }
581
585 public function exportHTMLFile($a_file_id)
586 {
587 $file_dir = $this->files_dir . "/file_" . $a_file_id;
588 ilUtil::makeDir($file_dir);
589
590 include_once("./Modules/File/classes/class.ilObjFile.php");
591 $file_obj = new ilObjFile($a_file_id, false);
592 $source_file = $file_obj->getDirectory($file_obj->getVersion()) . "/" . $file_obj->getFileName();
593 if (!is_file($source_file)) {
594 $source_file = $file_obj->getDirectory() . "/" . $file_obj->getFileName();
595 }
596 if (is_file($source_file)) {
597 copy($source_file, $file_dir . "/" . $file_obj->getFileName());
598 }
599 }
600
604 public function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
605 {
606 $file_dir = $this->files_dir . "/file_" . $a_file_id;
607 ilUtil::makeDir($file_dir);
608
609 if (is_file($a_source_file)) {
610 copy(
611 $a_source_file,
612 $file_dir . "/" . ilUtil::getASCIIFilename($a_file_name)
613 );
614 }
615 }
616}
user()
Definition: user.php:4
$tpl
Definition: ilias.php:10
if(strpos( $jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:32
$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)
ilCOPageHTMLExport constructor.
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()
static getLocaljQueryPath()
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
xslt_free(&$proc)
xslt_create()
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92