ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 function __construct($a_exp_dir)
23 {
24 $this->exp_dir = $a_exp_dir;
25 $this->mobs_dir = $a_exp_dir."/mobs";
26 $this->files_dir = $a_exp_dir."/files";
27 $this->tex_dir = $a_exp_dir."/teximg";
28 $this->content_style_dir = $a_exp_dir."/content_style";
29 $this->content_style_img_dir = $a_exp_dir."/content_style/images";
30
31 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
32 $this->services_dir = $a_exp_dir."/Services";
33 $this->media_service_dir = $this->services_dir."/MediaObjects";
34 $this->flv_dir = $a_exp_dir."/".ilPlayerUtil::getFlashVideoPlayerDirectory();
35 $this->mp3_dir = $this->media_service_dir."/flash_mp3_player";
36
37 $this->js_dir = $a_exp_dir.'/js';
38 $this->js_yahoo_dir = $a_exp_dir.'/js/yahoo';
39 $this->css_dir = $a_exp_dir.'/css';
40
41 $GLOBALS["teximgcnt"] = 0;
42 }
43
49 function setContentStyleId($a_val)
50 {
51 $this->content_style_id = $a_val;
52 }
53
60 {
62 }
63
71 {
72 ilUtil::makeDir($this->mobs_dir);
73 ilUtil::makeDir($this->files_dir);
74 ilUtil::makeDir($this->tex_dir);
75 ilUtil::makeDir($this->content_style_dir);
76 ilUtil::makeDir($this->content_style_img_dir);
77 ilUtil::makeDir($this->services_dir);
78 ilUtil::makeDir($this->media_service_dir);
79 ilUtil::makeDir($this->flv_dir);
80 ilUtil::makeDir($this->mp3_dir);
81
82 ilUtil::makeDir($this->js_dir);
83 ilUtil::makeDir($this->js_yahoo_dir);
84 ilUtil::makeDir($this->css_dir);
85 }
86
93 function exportStyles()
94 {
95 include_once "Services/Style/classes/class.ilObjStyleSheet.php";
96
97 // export content style sheet
98 if ($this->getContentStyleId() < 1)
99 {
100 $cont_stylesheet = "./Services/COPage/css/content.css";
101
102 $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
103 preg_match_all("/url\‍(([^\‍)]*)\‍)/",$css,$files);
104 foreach (array_unique($files[1]) as $fileref)
105 {
106 if (is_file(str_replace("..", ".", $fileref)))
107 {
108 copy(str_replace("..", ".", $fileref), $this->content_style_img_dir."/".basename($fileref));
109 }
110 $css = str_replace($fileref, "images/".basename($fileref),$css);
111 }
112 fwrite(fopen($this->content_style_dir."/content.css",'w'),$css);
113 }
114 else
115 {
116 $style = new ilObjStyleSheet($this->getContentStyleId());
117 $style->writeCSSFile($this->content_style_dir."/content.css", "images");
118 $style->copyImagesToDir($this->content_style_img_dir);
119 }
120
121 // export syntax highlighting style
122 $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
123 copy($syn_stylesheet, $this->exp_dir."/syntaxhighlight.css");
124 }
125
133 {
134
135 // basic js
136 copy('./Services/JavaScript/js/Basic.js', $this->js_dir.'/Basic.js');
137
138 copy('./Services/UIComponent/Overlay/js/ilOverlay.js',$this->js_dir.'/ilOverlay.js');
139
140 // jquery
141 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
142 copy(iljQueryUtil::getLocaljQueryPath(), $this->js_dir.'/jquery.js');
143 copy(iljQueryUtil::getLocaljQueryUIPath(), $this->js_dir.'/jquery-ui-min.js');
144 copy(iljQueryUtil::getLocalMaphilightPath(), $this->js_dir.'/maphilight.js');
145
146 // yui stuff we use
147 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
148 copy(ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
149 $this->js_yahoo_dir.'/yahoo-min.js');
150 copy(ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
151 $this->js_yahoo_dir.'/yahoo-dom-event.js');
152 copy(ilYuiUtil::getLocalPath('animation/animation-min.js'),
153 $this->js_yahoo_dir.'/animation-min.js');
154 copy(ilYuiUtil::getLocalPath('container/container-min.js'),
155 $this->js_yahoo_dir.'/container-min.js');
156 copy(ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'),
157 $this->css_dir.'/container.css');
158
159 // accordion
160 copy('./Services/Accordion/js/accordion.js',
161 $this->js_dir.'/accordion.js');
162 copy('./Services/Accordion/css/accordion.css',
163 $this->css_dir.'/accordion.css');
164
165 // page presentation js
166 copy('./Services/COPage/js/ilCOPagePres.js',
167 $this->js_dir.'/ilCOPagePres.js');
168
169 // tooltip
170 copy('./Services/UIComponent/Tooltip/js/ilTooltip.js',
171 $this->js_dir.'/ilTooltip.js');
172
173 // mediaelement.js
174 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
176
177 // matching question
178 copy('./Modules/TestQuestionPool/js/ilMatchingQuestion.js',
179 $this->js_dir.'/ilMatchingQuestion.js');
180 copy('./Modules/TestQuestionPool/templates/default/test_javascript.css',
181 $this->css_dir.'/test_javascript.css');
182
183
184// copy(ilPlayerUtil::getLocalMediaElementCssPath(),
185// $this->css_dir.'/mediaelementplayer.css');
186// copy(ilPlayerUtil::getLocalMediaElementJsPath(),
187// $this->js_dir.'/mediaelement-and-player.js');
188 }
189
196 function getPreparedMainTemplate($a_tpl = "")
197 {
198 global $ilUser;
199
200 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
201
202 if ($a_tpl != "")
203 {
204 $tpl = $a_tpl;
205 }
206 else
207 {
208 // template workaround: reset of template
209 $tpl = new ilTemplate("tpl.main.html", true, true);
210 }
211
212 // scripts needed
213 $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
214 "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js",
215 "./js/Basic.js", "./js/jquery.js", "./js/jquery-ui-min.js",
216 "./js/ilOverlay.js", "./js/accordion.js", "./js/ilCOPagePres.js",
217 "./js/ilTooltip.js", "./js/maphilight.js", "./js/ilMatchingQuestion.js");
218 $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
219
220 $mathJaxSetting = new ilSetting("MathJax");
221 $use_mathjax = $mathJaxSetting->get("enable");
222 if ($use_mathjax)
223 {
224 $scripts[] = $mathJaxSetting->get("path_to_mathjax");
225 }
226
227 foreach ($scripts as $script)
228 {
229 $tpl->setCurrentBlock("js_file");
230 $tpl->setVariable("JS_FILE", $script);
231 $tpl->parseCurrentBlock();
232 }
233
234 // css files needed
235 $style_name = $ilUser->prefs["style"].".css";
236 $css_files = array("./css/accordion.css", "./css/container.css",
237 "./content_style/content.css", "./style/".$style_name, "./css/test_javascript.css");
238 $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
239
240 foreach ($css_files as $css)
241 {
242 $tpl->setCurrentBlock("css_file");
243 $tpl->setVariable("CSS_FILE", $css);
244 $tpl->parseCurrentBlock();
245 }
246
247 return $tpl;
248 }
249
256 function collectPageElements($a_type, $a_id)
257 {
258 // collect media objects
259 $pg_mobs = ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
260 foreach($pg_mobs as $pg_mob)
261 {
262 $this->mobs[$pg_mob] = $pg_mob;
263 }
264
265 // collect all files
266 include_once("./Modules/File/classes/class.ilObjFile.php");
267 $files = ilObjFile::_getFilesOfObject($a_type, $a_id);
268 foreach($files as $f)
269 {
270 $this->files[$f] = $f;
271 }
272
273
274 $skill_tree = $ws_tree = null;
275
276 $pcs = ilPageContentUsage::getUsagesOfPage($a_id, $a_type);
277 foreach ($pcs as $pc)
278 {
279 // skils
280 if ($pc["type"] == "skmg")
281 {
282 $skill_id = $pc["id"];
283
284 // trying to find user id
285 $user_id = null;
286 switch($a_type)
287 {
288 case "prtf:pg":
289 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
290 $page = new ilPortfolioPage($a_id);
291 $user_id = $page->create_user;
292 break;
293
294 default:
295 // :TODO:
296 break;
297 }
298
299 if($user_id)
300 {
301 // we only need 1 instance each
302 if(!$skill_tree)
303 {
304 include_once "Services/Skill/classes/class.ilSkillTree.php";
305 $skill_tree = new ilSkillTree();
306
307 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
308
309 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
310 $ws_tree = new ilWorkspaceTree($user_id);
311 }
312
313 // walk skill tree
314 include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
315 $vtree = new ilVirtualSkillTree();
316 $tref_id = 0;
317 $skill_id = (int) $skill_id;
318 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
319 if (ilSkillTreeNode::_lookupType($skill_id) == "sktr")
320 {
321 include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
322 $tref_id = $skill_id;
323 $skill_id = ilSkillTemplateReference::_lookupTemplateId($skill_id);
324 }
325 $b_skills = $vtree->getSubTreeForCSkillId($skill_id.":".$tref_id, true);
326
327 foreach ($b_skills as $bs)
328 {
329 $skill = ilSkillTreeNodeFactory::getInstance($bs["skill_id"]);
330 $level_data = $skill->getLevelData();
331 foreach ($level_data as $k => $v)
332 {
333 // get assigned materials from personal skill
334 $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref_id"], $v["id"]);
335 if(sizeof($mat))
336 {
337 foreach($mat as $item)
338 {
339 $wsp_id = $item["wsp_id"];
340 $obj_id = $ws_tree->lookupObjectId($wsp_id);
341
342 // all possible material types for now
343 switch(ilObject::_lookupType($obj_id))
344 {
345 case "file":
346 $this->files[$obj_id] = $obj_id;
347 break;
348
349 case "tstv":
350 include_once "Modules/Test/classes/class.ilObjTestVerification.php";
351 $obj = new ilObjTestVerification($obj_id, false);
352 $this->files_direct[$obj_id] = array($obj->getFilePath(),
353 $obj->getOfflineFilename());
354 break;
355
356 case "excv":
357 include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
358 $obj = new ilObjExerciseVerification($obj_id, false);
359 $this->files_direct[$obj_id] = array($obj->getFilePath(),
360 $obj->getOfflineFilename());
361 break;
362
363 case "crsv":
364 include_once "Modules/Course/classes/Verification/class.ilObjCourseVerification.php";
365 $obj = new ilObjCourseVerification($obj_id, false);
366 $this->files_direct[$obj_id] = array($obj->getFilePath(),
367 $obj->getOfflineFilename());
368 break;
369
370 case "scov":
371 include_once "Modules/ScormAicc/classes/Verification/class.ilObjSCORMVerification.php";
372 $obj = new ilObjSCORMVerification($obj_id, false);
373 $this->files_direct[$obj_id] = array($obj->getFilePath(),
374 $obj->getOfflineFilename());
375 break;
376 }
377 }
378 }
379 }
380 }
381 }
382 }
383 }
384
385 }
386
394 {
395 // export all media objects
396 $linked_mobs = array();
397 foreach ($this->mobs as $mob)
398 {
399 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
400 {
401 $this->exportHTMLMOB($mob, $linked_mobs);
402 }
403 }
404 $linked_mobs2 = array(); // mobs linked in link areas
405 foreach ($linked_mobs as $mob)
406 {
407 if (ilObject::_exists($mob))
408 {
409 $this->exportHTMLMOB($mob, $linked_mobs2);
410 }
411 }
412
413 // export all file objects
414 foreach ($this->files as $file)
415 {
416 $this->exportHTMLFile($file);
417 }
418
419 // export all files (which are not objects
420 foreach ($this->files_direct as $file_id => $attr)
421 {
422 $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
423 }
424 }
425
429 function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
430 {
431 global $tpl;
432
433 $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
434 if (@is_dir($source_dir))
435 {
436 ilUtil::makeDir($this->mobs_dir."/mm_".$a_mob_id);
437 ilUtil::rCopy($source_dir, $this->mobs_dir."/mm_".$a_mob_id);
438 }
439
440 // #12930 - fullscreen
441 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
442 $mob_obj = new ilObjMediaObject($a_mob_id);
443 if ($mob_obj->hasFullscreenItem())
444 {
445 // render media object html
446 $xh = xslt_create();
447 $output = xslt_process(
448 $xh,
449 "arg:/_xml",
450 "arg:/_xsl",
451 NULL,
452 array(
453 "/_xml" =>
454 "<dummy>".
455 $mob_obj->getXML(IL_MODE_ALIAS).
456 $mob_obj->getXML(IL_MODE_OUTPUT).
457 "</dummy>",
458 "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
459 ),
460 array("mode"=>"fullscreen"));
461 xslt_free($xh);
462 unset($xh);
463
464 // render fullscreen html
465 $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
466 $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
467 $tpl->setCurrentBlock("ilMedia");
468 $tpl->setVariable("MEDIA_CONTENT", $output);
469 $output = $tpl->get();
470 unset($tpl);
471
472 // write file
473 $file = $this->exp_dir."/fullscreen_".$a_mob_id.".html";
474 if(!($fp = @fopen($file,"w+")))
475 {
476 die("<b>Error</b>: Could not open \"".$file."\" for writing".
477 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
478 }
479 chmod($file, 0770);
480 fwrite($fp, $output);
481 fclose($fp);
482 unset($fp);
483 unset($output);
484 }
485
486 $linked_mobs = $mob_obj->getLinkedMediaObjects();
487 $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
488 }
489
493 function exportHTMLFile($a_file_id)
494 {
495 $file_dir = $this->files_dir."/file_".$a_file_id;
496 ilUtil::makeDir($file_dir);
497
498 include_once("./Modules/File/classes/class.ilObjFile.php");
499 $file_obj = new ilObjFile($a_file_id, false);
500 $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
501 if (!is_file($source_file))
502 {
503 $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
504 }
505 if (is_file($source_file))
506 {
507 copy($source_file, $file_dir."/".$file_obj->getFileName());
508 }
509 }
510
514 function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
515 {
516 $file_dir = $this->files_dir."/file_".$a_file_id;
517 ilUtil::makeDir($file_dir);
518
519 if (is_file($a_source_file))
520 {
521 copy($a_source_file,
522 $file_dir."/".ilUtil::getASCIIFilename($a_file_name));
523 }
524 }
525
526}
527
528?>
print $file
global $tpl
Definition: ilias.php:8
const IL_MODE_ALIAS
const IL_MODE_OUTPUT
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.
exportPageElements()
Export page elements.
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.
Class ilObjFile.
_getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
Class ilObjMediaObject.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
Class ilObjStyleSheet.
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
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.
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 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.
getLocalMaphilightPath()
Get local path of maphilight file.
getLocaljQueryPath()
Get local path of jQuery file.
getLocaljQueryUIPath()
Get local path of jQuery UI file.
$GLOBALS['ct_recipient']
xslt_free(&$proc)
xslt_create()
global $ilUser
Definition: imgupload.php:15
if(strpos( $jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34