ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
59  function getContentStyleId()
60  {
62  }
63 
70  function createDirectories()
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  // export flv/mp3 player
135  //copy(ilPlayerUtil::getFlashVideoPlayerFilename(true),
136  // $this->js_dir."/".ilPlayerUtil::getFlashVideoPlayerFilename());
137  //copy("./Services/MediaObjects/flash_mp3_player/mp3player.swf",
138  // $this->mp3_dir."/mp3player.swf");
139 
140  // basic js
141  copy('./Services/JavaScript/js/Basic.js', $this->js_dir.'/Basic.js');
142 
143  copy('./Services/UIComponent/Overlay/js/ilOverlay.js',$this->js_dir.'/ilOverlay.js');
144 
145  // jquery
146  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
147  copy(iljQueryUtil::getLocaljQueryPath(), $this->js_dir.'/jquery.js');
148  copy(iljQueryUtil::getLocaljQueryUIPath(), $this->js_dir.'/jquery-ui-min.js');
149  copy(iljQueryUtil::getLocalMaphilightPath(), $this->js_dir.'/maphilight.js');
150 
151  // yui stuff we use
152  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
153  copy(ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
154  $this->js_yahoo_dir.'/yahoo-min.js');
155  copy(ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
156  $this->js_yahoo_dir.'/yahoo-dom-event.js');
157  copy(ilYuiUtil::getLocalPath('animation/animation-min.js'),
158  $this->js_yahoo_dir.'/animation-min.js');
159  copy(ilYuiUtil::getLocalPath('container/container-min.js'),
160  $this->js_yahoo_dir.'/container-min.js');
161  copy(ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'),
162  $this->css_dir.'/container.css');
163 
164  // accordion
165  copy('./Services/Accordion/js/accordion.js',
166  $this->js_dir.'/accordion.js');
167  copy('./Services/Accordion/css/accordion.css',
168  $this->css_dir.'/accordion.css');
169 
170  // page presentation js
171  copy('./Services/COPage/js/ilCOPagePres.js',
172  $this->js_dir.'/ilCOPagePres.js');
173 
174  // tooltip
175  copy('./Services/UIComponent/Tooltip/js/ilTooltip.js',
176  $this->js_dir.'/ilTooltip.js');
177 
178  // mediaelement.js
179  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
181 
182 // copy(ilPlayerUtil::getLocalMediaElementCssPath(),
183 // $this->css_dir.'/mediaelementplayer.css');
184 // copy(ilPlayerUtil::getLocalMediaElementJsPath(),
185 // $this->js_dir.'/mediaelement-and-player.js');
186  }
187 
194  function getPreparedMainTemplate($a_tpl = "")
195  {
196  global $ilUser;
197 
198  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
199 
200  if ($a_tpl != "")
201  {
202  $tpl = $a_tpl;
203  }
204  else
205  {
206  // template workaround: reset of template
207  $tpl = new ilTemplate("tpl.main.html", true, true);
208  }
209 
210  // scripts needed
211  $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
212  "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js",
213  "./js/Basic.js", "./js/jquery.js", "./js/jquery-ui-min.js",
214  "./js/ilOverlay.js", "./js/accordion.js", "./js/ilCOPagePres.js",
215  "./js/ilTooltip.js", "./js/maphilight.js");
216  $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
217 
218  $mathJaxSetting = new ilSetting("MathJax");
219  $use_mathjax = $mathJaxSetting->get("enable");
220  if ($use_mathjax)
221  {
222  $scripts[] = $mathJaxSetting->get("path_to_mathjax");
223  }
224 
225  foreach ($scripts as $script)
226  {
227  $tpl->setCurrentBlock("js_file");
228  $tpl->setVariable("JS_FILE", $script);
229  $tpl->parseCurrentBlock();
230  }
231 
232  // css files needed
233  $style_name = $ilUser->prefs["style"].".css";
234  $css_files = array("./css/accordion.css", "./css/container.css",
235  "./content_style/content.css", "./style/".$style_name);
236  $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
237 
238  foreach ($css_files as $css)
239  {
240  $tpl->setCurrentBlock("css_file");
241  $tpl->setVariable("CSS_FILE", $css);
242  $tpl->parseCurrentBlock();
243  }
244 
245  return $tpl;
246  }
247 
254  function collectPageElements($a_type, $a_id)
255  {
256  // collect media objects
257  $pg_mobs = ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
258  foreach($pg_mobs as $pg_mob)
259  {
260  $this->mobs[$pg_mob] = $pg_mob;
261  }
262 
263  // collect all files
264  include_once("./Modules/File/classes/class.ilObjFile.php");
265  $files = ilObjFile::_getFilesOfObject($a_type, $a_id);
266  foreach($files as $f)
267  {
268  $this->files[$f] = $f;
269  }
270 
271 
272  $skill_tree = $ws_tree = null;
273 
274  $pcs = ilPageContentUsage::getUsagesOfPage($a_id, $a_type);
275  foreach ($pcs as $pc)
276  {
277  // skils
278  if ($pc["type"] == "skmg")
279  {
280  $skill_id = $pc["id"];
281 
282  // get user id from portfolio page
283  include_once "Services/Portfolio/classes/class.ilPortfolioPage.php";
284  $page = new ilPortfolioPage(0, $a_id);
285  $user_id = $page->create_user;
286 
287  // we only need 1 instance each
288  if(!$skill_tree)
289  {
290  include_once "Services/Skill/classes/class.ilSkillTree.php";
291  $skill_tree = new ilSkillTree();
292 
293  include_once "Services/Skill/classes/class.ilPersonalSkill.php";
294 
295  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
296  $ws_tree = new ilWorkspaceTree($user_id);
297  }
298 
299  // walk skill tree
300  $b_skills = ilSkillTreeNode::getSkillTreeNodes($skill_id, true);
301  foreach ($b_skills as $bs)
302  {
303  $skill = ilSkillTreeNodeFactory::getInstance($bs["id"]);
304  $level_data = $skill->getLevelData();
305  foreach ($level_data as $k => $v)
306  {
307  // get assigned materials from personal skill
308  $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref"], $v["id"]);
309  if(sizeof($mat))
310  {
311  foreach($mat as $item)
312  {
313  $wsp_id = $item["wsp_id"];
314  $obj_id = $ws_tree->lookupObjectId($wsp_id);
315 
316  // all possible material types for now
317  switch(ilObject::_lookupType($obj_id))
318  {
319  case "file":
320  $this->files[$obj_id] = $obj_id;
321  break;
322 
323  case "tstv":
324  include_once "Modules/Test/classes/class.ilObjTestVerification.php";
325  $obj = new ilObjTestVerification($obj_id, false);
326  $this->files_direct[$obj_id] = array($obj->getFilePath(),
327  $obj->getOfflineFilename());
328  break;
329 
330  case "excv":
331  include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
332  $obj = new ilObjExerciseVerification($obj_id, false);
333  $this->files_direct[$obj_id] = array($obj->getFilePath(),
334  $obj->getOfflineFilename());
335  break;
336  }
337  }
338  }
339  }
340  }
341 
342  }
343  }
344 
345  }
346 
354  {
355  // export all media objects
356  $linked_mobs = array();
357  foreach ($this->mobs as $mob)
358  {
359  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
360  {
361  $this->exportHTMLMOB($mob, $linked_mobs);
362  }
363  }
364  $linked_mobs2 = array(); // mobs linked in link areas
365  foreach ($linked_mobs as $mob)
366  {
367  if (ilObject::_exists($mob))
368  {
369  $this->exportHTMLMOB($mob, $linked_mobs2);
370  }
371  }
372 
373  // export all file objects
374  foreach ($this->files as $file)
375  {
376  $this->exportHTMLFile($file);
377  }
378 
379  // export all files (which are not objects
380  foreach ($this->files_direct as $file_id => $attr)
381  {
382  $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
383  }
384  }
385 
389  function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
390  {
391  global $tpl;
392 
393  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
394  if (@is_dir($source_dir))
395  {
396  ilUtil::makeDir($this->mobs_dir."/mm_".$a_mob_id);
397  ilUtil::rCopy($source_dir, $this->mobs_dir."/mm_".$a_mob_id);
398  }
399 
400  // #12930 - fullscreen
401  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
402  $mob_obj = new ilObjMediaObject($a_mob_id);
403  if ($mob_obj->hasFullscreenItem())
404  {
405  // render media object html
406  $xh = xslt_create();
407  $output = xslt_process(
408  $xh,
409  "arg:/_xml",
410  "arg:/_xsl",
411  NULL,
412  array(
413  "/_xml" =>
414  "<dummy>".
415  $mob_obj->getXML(IL_MODE_ALIAS).
416  $mob_obj->getXML(IL_MODE_OUTPUT).
417  "</dummy>",
418  "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
419  ),
420  array("mode"=>"fullscreen"));
421  xslt_free($xh);
422  unset($xh);
423 
424  // render fullscreen html
425  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
426  $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
427  $tpl->setCurrentBlock("ilMedia");
428  $tpl->setVariable("MEDIA_CONTENT", $output);
429  $output = $tpl->get();
430  unset($tpl);
431 
432  // write file
433  $file = $this->exp_dir."/fullscreen_".$a_mob_id.".html";
434  if(!($fp = @fopen($file,"w+")))
435  {
436  die("<b>Error</b>: Could not open \"".$file."\" for writing".
437  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
438  }
439  chmod($file, 0770);
440  fwrite($fp, $output);
441  fclose($fp);
442  unset($fp);
443  unset($output);
444  }
445 
446  $linked_mobs = $mob_obj->getLinkedMediaObjects();
447  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
448  }
449 
453  function exportHTMLFile($a_file_id)
454  {
455  $file_dir = $this->files_dir."/file_".$a_file_id;
456  ilUtil::makeDir($file_dir);
457 
458  include_once("./Modules/File/classes/class.ilObjFile.php");
459  $file_obj = new ilObjFile($a_file_id, false);
460  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
461  if (!is_file($source_file))
462  {
463  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
464  }
465  if (is_file($source_file))
466  {
467  copy($source_file, $file_dir."/".$file_obj->getFileName());
468  }
469  }
470 
474  function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
475  {
476  $file_dir = $this->files_dir."/file_".$a_file_id;
477  ilUtil::makeDir($file_dir);
478 
479  if (is_file($a_source_file))
480  {
481  copy($a_source_file,
482  $file_dir."/".ilUtil::getASCIIFilename($a_file_name));
483  }
484  }
485 
486 }
487 
488 ?>