ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
147  $style = new ilObjStyleSheet($this->getContentStyleId());
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.min.js"))) {
266  copy($p, $this->js_dir . '/linkify.min.js');
267  }
268  if (is_int(strpos($p, "linkify-jquery.min.js"))) {
269  copy($p, $this->js_dir . '/linkify-jquery.min.js');
270  }
271  }
272 
273 
274  // copy(ilPlayerUtil::getLocalMediaElementCssPath(),
275 // $this->css_dir.'/mediaelementplayer.css');
276 // copy(ilPlayerUtil::getLocalMediaElementJsPath(),
277 // $this->js_dir.'/mediaelement-and-player.js');
278  }
279 
286  public function getPreparedMainTemplate($a_tpl = "")
287  {
288  $this->log->debug("get main template");
289 
290  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
291 
292  if ($a_tpl != "") {
293  $tpl = $a_tpl;
294  } else {
295  // template workaround: reset of template
296  $tpl = new ilTemplate("tpl.main.html", true, true);
297  }
298 
299  // scripts needed
300  $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
301  "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js", "./js/jquery.js",
302  "./js/Basic.js", "./js/jquery-ui-min.js",
303  "./js/ilOverlay.js", "./js/ilCOPagePres.js",
304  "./js/ilTooltip.js", "./js/maphilight.js", "./js/ilMatchingQuestion.js", "./js/ilAssMultipleChoice.js",
305  "./js/ilExtLink.js", "./js/linkify.js");
306  $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
307 
308  $mathJaxSetting = new ilSetting("MathJax");
309  $use_mathjax = $mathJaxSetting->get("enable");
310  if ($use_mathjax) {
311  $scripts[] = $mathJaxSetting->get("path_to_mathjax");
312  }
313 
314  // accordion
315  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
317  $scripts[] = $f;
318  }
319 
320  foreach ($scripts as $script) {
321  $tpl->setCurrentBlock("js_file");
322  $tpl->setVariable("JS_FILE", $script);
323  $tpl->parseCurrentBlock();
324  }
325 
326  // css files needed
327  $style_name = $this->user->prefs["style"] . ".css";
328  $css_files = array("./css/container.css",
329  "./content_style/content.css", "./style/" . $style_name, "./css/test_javascript.css");
330  $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
331 
332  // accordion
333  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
334  foreach (ilAccordionGUI::getLocalCssFiles() as $f) {
335  $css_files[] = $f;
336  }
337 
338 
339  foreach ($css_files as $css) {
340  $tpl->setCurrentBlock("css_file");
341  $tpl->setVariable("CSS_FILE", $css);
342  $tpl->parseCurrentBlock();
343  }
344 
345  return $tpl;
346  }
347 
354  public function collectPageElements($a_type, $a_id)
355  {
356  $this->log->debug("collect page elements");
357 
358  // collect media objects
359  $pg_mobs = ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
360  foreach ($pg_mobs as $pg_mob) {
361  $this->mobs[$pg_mob] = $pg_mob;
362  }
363 
364  // collect all files
365  include_once("./Modules/File/classes/class.ilObjFile.php");
367  foreach ($files as $f) {
368  $this->files[$f] = $f;
369  }
370 
371 
372  $skill_tree = $ws_tree = null;
373 
375  foreach ($pcs as $pc) {
376  // skils
377  if ($pc["type"] == "skmg") {
378  $skill_id = $pc["id"];
379 
380  // trying to find user id
381  $user_id = null;
382  switch ($a_type) {
383  case "prtf:pg":
384  include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
385  $page = new ilPortfolioPage($a_id);
386  $user_id = $page->create_user;
387  break;
388 
389  default:
390  // :TODO:
391  break;
392  }
393 
394  if ($user_id) {
395  // we only need 1 instance each
396  if (!$skill_tree) {
397  include_once "Services/Skill/classes/class.ilSkillTree.php";
398  $skill_tree = new ilSkillTree();
399 
400  include_once "Services/Skill/classes/class.ilPersonalSkill.php";
401 
402  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
403  $ws_tree = new ilWorkspaceTree($user_id);
404  }
405 
406  // walk skill tree
407  include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
408  $vtree = new ilVirtualSkillTree();
409  $tref_id = 0;
410  $skill_id = (int) $skill_id;
411  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
412  if (ilSkillTreeNode::_lookupType($skill_id) == "sktr") {
413  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
414  $tref_id = $skill_id;
415  $skill_id = ilSkillTemplateReference::_lookupTemplateId($skill_id);
416  }
417  $b_skills = $vtree->getSubTreeForCSkillId($skill_id . ":" . $tref_id, true);
418 
419  foreach ($b_skills as $bs) {
420  $skill = ilSkillTreeNodeFactory::getInstance($bs["skill_id"]);
421  $level_data = $skill->getLevelData();
422  foreach ($level_data as $k => $v) {
423  // get assigned materials from personal skill
424  $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref_id"], $v["id"]);
425  if (sizeof($mat)) {
426  foreach ($mat as $item) {
427  $wsp_id = $item["wsp_id"];
428  $obj_id = $ws_tree->lookupObjectId($wsp_id);
429 
430  // all possible material types for now
431  switch (ilObject::_lookupType($obj_id)) {
432  case "file":
433  $this->files[$obj_id] = $obj_id;
434  break;
435 
436  case "tstv":
437  include_once "Modules/Test/classes/class.ilObjTestVerification.php";
438  $obj = new ilObjTestVerification($obj_id, false);
439  $this->files_direct[$obj_id] = array($obj->getFilePath(),
440  $obj->getOfflineFilename());
441  break;
442 
443  case "excv":
444  include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
445  $obj = new ilObjExerciseVerification($obj_id, false);
446  $this->files_direct[$obj_id] = array($obj->getFilePath(),
447  $obj->getOfflineFilename());
448  break;
449 
450  case "crsv":
451  include_once "Modules/Course/classes/Verification/class.ilObjCourseVerification.php";
452  $obj = new ilObjCourseVerification($obj_id, false);
453  $this->files_direct[$obj_id] = array($obj->getFilePath(),
454  $obj->getOfflineFilename());
455  break;
456 
457  case "scov":
458  include_once "Modules/ScormAicc/classes/Verification/class.ilObjSCORMVerification.php";
459  $obj = new ilObjSCORMVerification($obj_id, false);
460  $this->files_direct[$obj_id] = array($obj->getFilePath(),
461  $obj->getOfflineFilename());
462  break;
463  }
464  }
465  }
466  }
467  }
468  }
469  }
470  }
471  }
472 
479  public function exportPageElements($a_update_callback = null)
480  {
481  $this->log->debug("export page elements");
482 
483  $total = count($this->mobs) + count($this->files) + count($this->files_direct);
484  $cnt = 0;
485 
486  // export all media objects
487  $linked_mobs = array();
488  foreach ($this->mobs as $mob) {
489  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
490  $this->exportHTMLMOB($mob, $linked_mobs);
491  }
492  if (is_callable($a_update_callback)) {
493  $cnt++;
494  $a_update_callback($total, $cnt);
495  }
496  }
497  $linked_mobs2 = array(); // mobs linked in link areas
498  foreach ($linked_mobs as $mob) {
499  if (ilObject::_exists($mob)) {
500  $this->exportHTMLMOB($mob, $linked_mobs2);
501  }
502  }
503 
504  // export all file objects
505  foreach ($this->files as $file) {
506  $this->exportHTMLFile($file);
507  if (is_callable($a_update_callback)) {
508  $cnt++;
509  $a_update_callback($total, $cnt);
510  }
511  }
512 
513  // export all files (which are not objects
514  foreach ($this->files_direct as $file_id => $attr) {
515  $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
516  if (is_callable($a_update_callback)) {
517  $cnt++;
518  $a_update_callback($total, $cnt);
519  }
520  }
521  }
522 
526  public function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
527  {
528  $this->log->debug("export html mobs");
529 
530  $source_dir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $a_mob_id;
531  if (is_dir($source_dir)) {
532  ilUtil::makeDir($this->mobs_dir . "/mm_" . $a_mob_id);
533  ilUtil::rCopy($source_dir, $this->mobs_dir . "/mm_" . $a_mob_id);
534  }
535 
536  // #12930 - fullscreen
537  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
538  $mob_obj = new ilObjMediaObject($a_mob_id);
539  if ($mob_obj->hasFullscreenItem()) {
540  // render media object html
541  $xh = xslt_create();
542  $output = xslt_process(
543  $xh,
544  "arg:/_xml",
545  "arg:/_xsl",
546  null,
547  array(
548  "/_xml" =>
549  "<dummy>" .
550  $mob_obj->getXML(IL_MODE_ALIAS) .
551  $mob_obj->getXML(IL_MODE_OUTPUT) .
552  "</dummy>",
553  "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
554  ),
555  array("mode" => "fullscreen")
556  );
557  xslt_free($xh);
558  unset($xh);
559 
560  // render fullscreen html
561  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
562  $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
563  $tpl->setCurrentBlock("ilMedia");
564  $tpl->setVariable("MEDIA_CONTENT", $output);
565  $output = $tpl->get();
566  unset($tpl);
567 
568  // write file
569  $file = $this->exp_dir . "/fullscreen_" . $a_mob_id . ".html";
570  if (!($fp = @fopen($file, "w+"))) {
571  die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
572  " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
573  }
574  chmod($file, 0770);
575  fwrite($fp, $output);
576  fclose($fp);
577  unset($fp);
578  unset($output);
579  }
580 
581  $linked_mobs = $mob_obj->getLinkedMediaObjects();
582  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
583  }
584 
588  public function exportHTMLFile($a_file_id)
589  {
590  $file_dir = $this->files_dir . "/file_" . $a_file_id;
591  ilUtil::makeDir($file_dir);
592 
593  include_once("./Modules/File/classes/class.ilObjFile.php");
594  $file_obj = new ilObjFile($a_file_id, false);
595  $source_file = $file_obj->getDirectory($file_obj->getVersion()) . "/" . $file_obj->getFileName();
596  if (!is_file($source_file)) {
597  $source_file = $file_obj->getDirectory() . "/" . $file_obj->getFileName();
598  }
599  if (is_file($source_file)) {
600  copy($source_file, $file_dir . "/" . $file_obj->getFileName());
601  }
602  }
603 
607  public function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
608  {
609  $file_dir = $this->files_dir . "/file_" . $a_file_id;
610  ilUtil::makeDir($file_dir);
611 
612  if (is_file($a_source_file)) {
613  copy(
614  $a_source_file,
615  $file_dir . "/" . ilUtil::getASCIIFilename($a_file_name)
616  );
617  }
618  }
619 }
xslt_create()
static getCssFilePaths()
Get css file paths.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
setContentStyleId($a_val)
Set content style id.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
$style
Definition: example_012.php:70
exportHTMLFile($a_file_id)
Export file object.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $DIC
Definition: saml.php:7
HTML export class for pages.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
Skill tree.
$tpl
Definition: ilias.php:10
xslt_free(&$proc)
static getLocaljQueryUIPath()
getContentStyleId()
Get content style id.
static getLocalJsPaths()
Get paths of necessary js files.
exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
Export file from path.
getPreparedMainTemplate($a_tpl="")
Get prepared main template.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
user()
Definition: user.php:4
$total
Definition: Utf8Test.php:87
Tree handler for personal workspace.
static getLocalJavascriptFiles()
static _lookupType($a_obj_id)
Lookup Type.
static getJsFilePaths()
Get js file paths.
$a_type
Definition: workflow.php:92
__construct($a_exp_dir)
ilCOPageHTMLExport constructor.
createDirectories()
Create directories.
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.
special template class to simplify handling of ITX/PEAR
static getFlashVideoPlayerDirectory()
Get flash video player directory.
exportSupportScripts()
Export support scripts.
Page for user portfolio.
static _lookupTemplateId($a_obj_id)
Lookup template ID.
Class ilObjMediaObject.
static getSyntaxStylePath()
get syntax style path
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
const IL_MODE_ALIAS
static _lookupType($a_id, $a_reference=false)
lookup object type
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getLocalPath($a_name="")
Get local path of a YUI js file.
static getAssignedMaterial($a_user_id, $a_tref_id, $a_level)
Get assigned material (for a skill level and user)
static copyPlayerFilesToTargetDirectory($a_target_dir)
Copy css files to target dir.
Class ilObjStyleSheet.
collectPageElements($a_type, $a_id)
Collect page elements (that need to be exported separately)
static getLocalMaphilightPath()
Get local path of maphilight file.
const IL_MODE_OUTPUT
static getLogger($a_component_id)
Get component logger.
if(strpos($jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:32
exportStyles()
Export content style.
exportHTMLMOB($a_mob_id, &$a_linked_mobs)
Export media object to html.
static getLocaljQueryPath()
static getWebspaceDir($mode="filesystem")
get webspace directory
exportPageElements($a_update_callback=null)
Export page elements.