ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
67  function getContentStyleId()
68  {
70  }
71 
78  function createDirectories()
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  include_once "Services/Style/classes/class.ilObjStyleSheet.php";
104  $this->log->debug("export styles");
105 
106  // export content style sheet
107  if ($this->getContentStyleId() < 1)
108  {
109  $cont_stylesheet = "./Services/COPage/css/content.css";
110 
111  $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
112  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
113  foreach (array_unique($files[1]) as $fileref)
114  {
115  if (is_file(str_replace("..", ".", $fileref)))
116  {
117  copy(str_replace("..", ".", $fileref), $this->content_style_img_dir."/".basename($fileref));
118  }
119  $css = str_replace($fileref, "images/".basename($fileref),$css);
120  }
121  fwrite(fopen($this->content_style_dir."/content.css",'w'),$css);
122  }
123  else
124  {
125  $style = new ilObjStyleSheet($this->getContentStyleId());
126  $style->writeCSSFile($this->content_style_dir."/content.css", "images");
127  $style->copyImagesToDir($this->content_style_img_dir);
128  }
129 
130  // export syntax highlighting style
131  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
132  copy($syn_stylesheet, $this->exp_dir."/syntaxhighlight.css");
133  }
134 
144  {
145  $this->log->debug("export scripts");
146 
147  // basic js
148  copy('./Services/JavaScript/js/Basic.js', $this->js_dir.'/Basic.js');
149 
150  copy('./Services/UIComponent/Overlay/js/ilOverlay.js',$this->js_dir.'/ilOverlay.js');
151 
152  // jquery
153  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
154  copy(iljQueryUtil::getLocaljQueryPath(), $this->js_dir.'/jquery.js');
155  copy(iljQueryUtil::getLocaljQueryUIPath(), $this->js_dir.'/jquery-ui-min.js');
156  copy(iljQueryUtil::getLocalMaphilightPath(), $this->js_dir.'/maphilight.js');
157 
158  // yui stuff we use
159  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
160  copy(ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
161  $this->js_yahoo_dir.'/yahoo-min.js');
162  copy(ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
163  $this->js_yahoo_dir.'/yahoo-dom-event.js');
164  copy(ilYuiUtil::getLocalPath('animation/animation-min.js'),
165  $this->js_yahoo_dir.'/animation-min.js');
166  copy(ilYuiUtil::getLocalPath('container/container-min.js'),
167  $this->js_yahoo_dir.'/container-min.js');
168  copy(ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'),
169  $this->css_dir.'/container.css');
170 
171  // accordion
172  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
174  {
175  $tfile = $this->exp_dir."/".$f;
176  ilUtil::makeDirParents(dirname($tfile));
177  copy($f, $tfile);
178  }
179  foreach (ilAccordionGUI::getLocalCssFiles() as $f)
180  {
181  $tfile = $this->exp_dir."/".$f;
182  ilUtil::makeDirParents(dirname($tfile));
183  copy($f, $tfile);
184  }
185 
186  copy('./Services/Accordion/js/accordion.js',
187  $this->js_dir.'/accordion.js');
188  copy('./Services/Accordion/css/accordion.css',
189  $this->css_dir.'/accordion.css');
190 
191  // page presentation js
192  copy('./Services/COPage/js/ilCOPagePres.js',
193  $this->js_dir.'/ilCOPagePres.js');
194 
195  // tooltip
196  copy('./Services/UIComponent/Tooltip/js/ilTooltip.js',
197  $this->js_dir.'/ilTooltip.js');
198 
199  // mediaelement.js
200  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
202 
203  // matching question
204  copy('./Modules/TestQuestionPool/js/ilMatchingQuestion.js',
205  $this->js_dir.'/ilMatchingQuestion.js');
206  copy('./Modules/TestQuestionPool/templates/default/test_javascript.css',
207  $this->css_dir.'/test_javascript.css');
208 
209  // auto linking js
210  include_once("./Services/Link/classes/class.ilLinkifyUtil.php");
211  foreach (ilLinkifyUtil::getLocalJsPaths() as $p)
212  {
213  if (is_int(strpos($p, "ExtLink")))
214  {
215  copy($p, $this->js_dir.'/ilExtLink.js');
216  }
217  if (is_int(strpos($p, "linkify")))
218  {
219  copy($p, $this->js_dir.'/linkify.js');
220  }
221  }
222 
223 
224 // copy(ilPlayerUtil::getLocalMediaElementCssPath(),
225 // $this->css_dir.'/mediaelementplayer.css');
226 // copy(ilPlayerUtil::getLocalMediaElementJsPath(),
227 // $this->js_dir.'/mediaelement-and-player.js');
228  }
229 
236  function getPreparedMainTemplate($a_tpl = "")
237  {
238  global $ilUser;
239 
240  $this->log->debug("get main template");
241 
242  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
243 
244  if ($a_tpl != "")
245  {
246  $tpl = $a_tpl;
247  }
248  else
249  {
250  // template workaround: reset of template
251  $tpl = new ilTemplate("tpl.main.html", true, true);
252  }
253 
254  // scripts needed
255  $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
256  "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js", "./js/jquery.js",
257  "./js/Basic.js", "./js/jquery-ui-min.js",
258  "./js/ilOverlay.js", "./js/ilCOPagePres.js",
259  "./js/ilTooltip.js", "./js/maphilight.js", "./js/ilMatchingQuestion.js",
260  "./js/ilExtLink.js", "./js/linkify.js");
261  $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
262 
263  $mathJaxSetting = new ilSetting("MathJax");
264  $use_mathjax = $mathJaxSetting->get("enable");
265  if ($use_mathjax)
266  {
267  $scripts[] = $mathJaxSetting->get("path_to_mathjax");
268  }
269 
270  // accordion
271  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
273  {
274  $scripts[] = $f;
275  }
276 
277  foreach ($scripts as $script)
278  {
279  $tpl->setCurrentBlock("js_file");
280  $tpl->setVariable("JS_FILE", $script);
281  $tpl->parseCurrentBlock();
282  }
283 
284  // css files needed
285  $style_name = $ilUser->prefs["style"].".css";
286  $css_files = array("./css/container.css",
287  "./content_style/content.css", "./style/".$style_name, "./css/test_javascript.css");
288  $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
289 
290  // accordion
291  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
292  foreach (ilAccordionGUI::getLocalCssFiles() as $f)
293  {
294  $css_files[] = $f;
295  }
296 
297 
298  foreach ($css_files as $css)
299  {
300  $tpl->setCurrentBlock("css_file");
301  $tpl->setVariable("CSS_FILE", $css);
302  $tpl->parseCurrentBlock();
303  }
304 
305  return $tpl;
306  }
307 
314  function collectPageElements($a_type, $a_id)
315  {
316  $this->log->debug("collect page elements");
317 
318  // collect media objects
319  $pg_mobs = ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
320  foreach($pg_mobs as $pg_mob)
321  {
322  $this->mobs[$pg_mob] = $pg_mob;
323  }
324 
325  // collect all files
326  include_once("./Modules/File/classes/class.ilObjFile.php");
327  $files = ilObjFile::_getFilesOfObject($a_type, $a_id);
328  foreach($files as $f)
329  {
330  $this->files[$f] = $f;
331  }
332 
333 
334  $skill_tree = $ws_tree = null;
335 
336  $pcs = ilPageContentUsage::getUsagesOfPage($a_id, $a_type);
337  foreach ($pcs as $pc)
338  {
339  // skils
340  if ($pc["type"] == "skmg")
341  {
342  $skill_id = $pc["id"];
343 
344  // trying to find user id
345  $user_id = null;
346  switch($a_type)
347  {
348  case "prtf:pg":
349  include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
350  $page = new ilPortfolioPage($a_id);
351  $user_id = $page->create_user;
352  break;
353 
354  default:
355  // :TODO:
356  break;
357  }
358 
359  if($user_id)
360  {
361  // we only need 1 instance each
362  if(!$skill_tree)
363  {
364  include_once "Services/Skill/classes/class.ilSkillTree.php";
365  $skill_tree = new ilSkillTree();
366 
367  include_once "Services/Skill/classes/class.ilPersonalSkill.php";
368 
369  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
370  $ws_tree = new ilWorkspaceTree($user_id);
371  }
372 
373  // walk skill tree
374  include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
375  $vtree = new ilVirtualSkillTree();
376  $tref_id = 0;
377  $skill_id = (int) $skill_id;
378  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
379  if (ilSkillTreeNode::_lookupType($skill_id) == "sktr")
380  {
381  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
382  $tref_id = $skill_id;
383  $skill_id = ilSkillTemplateReference::_lookupTemplateId($skill_id);
384  }
385  $b_skills = $vtree->getSubTreeForCSkillId($skill_id.":".$tref_id, true);
386 
387  foreach ($b_skills as $bs)
388  {
389  $skill = ilSkillTreeNodeFactory::getInstance($bs["skill_id"]);
390  $level_data = $skill->getLevelData();
391  foreach ($level_data as $k => $v)
392  {
393  // get assigned materials from personal skill
394  $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref_id"], $v["id"]);
395  if(sizeof($mat))
396  {
397  foreach($mat as $item)
398  {
399  $wsp_id = $item["wsp_id"];
400  $obj_id = $ws_tree->lookupObjectId($wsp_id);
401 
402  // all possible material types for now
403  switch(ilObject::_lookupType($obj_id))
404  {
405  case "file":
406  $this->files[$obj_id] = $obj_id;
407  break;
408 
409  case "tstv":
410  include_once "Modules/Test/classes/class.ilObjTestVerification.php";
411  $obj = new ilObjTestVerification($obj_id, false);
412  $this->files_direct[$obj_id] = array($obj->getFilePath(),
413  $obj->getOfflineFilename());
414  break;
415 
416  case "excv":
417  include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
418  $obj = new ilObjExerciseVerification($obj_id, false);
419  $this->files_direct[$obj_id] = array($obj->getFilePath(),
420  $obj->getOfflineFilename());
421  break;
422 
423  case "crsv":
424  include_once "Modules/Course/classes/Verification/class.ilObjCourseVerification.php";
425  $obj = new ilObjCourseVerification($obj_id, false);
426  $this->files_direct[$obj_id] = array($obj->getFilePath(),
427  $obj->getOfflineFilename());
428  break;
429 
430  case "scov":
431  include_once "Modules/ScormAicc/classes/Verification/class.ilObjSCORMVerification.php";
432  $obj = new ilObjSCORMVerification($obj_id, false);
433  $this->files_direct[$obj_id] = array($obj->getFilePath(),
434  $obj->getOfflineFilename());
435  break;
436  }
437  }
438  }
439  }
440  }
441  }
442  }
443  }
444 
445  }
446 
453  function exportPageElements($a_update_callback = null)
454  {
455  $this->log->debug("export page elements");
456 
457  $total = count($this->mobs) + count($this->files) + count($this->files_direct);
458  $cnt = 0;
459 
460  // export all media objects
461  $linked_mobs = array();
462  foreach ($this->mobs as $mob)
463  {
464  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
465  {
466  $this->exportHTMLMOB($mob, $linked_mobs);
467  }
468  if (is_callable($a_update_callback))
469  {
470  $cnt++;
471  $a_update_callback($total, $cnt);
472  }
473  }
474  $linked_mobs2 = array(); // mobs linked in link areas
475  foreach ($linked_mobs as $mob)
476  {
477  if (ilObject::_exists($mob))
478  {
479  $this->exportHTMLMOB($mob, $linked_mobs2);
480  }
481  }
482 
483  // export all file objects
484  foreach ($this->files as $file)
485  {
486  $this->exportHTMLFile($file);
487  if (is_callable($a_update_callback))
488  {
489  $cnt++;
490  $a_update_callback($total, $cnt);
491  }
492  }
493 
494  // export all files (which are not objects
495  foreach ($this->files_direct as $file_id => $attr)
496  {
497  $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
498  if (is_callable($a_update_callback))
499  {
500  $cnt++;
501  $a_update_callback($total, $cnt);
502  }
503  }
504  }
505 
509  function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
510  {
511  global $tpl;
512 
513  $this->log->debug("export html mobs");
514 
515  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
516  if (@is_dir($source_dir))
517  {
518  ilUtil::makeDir($this->mobs_dir."/mm_".$a_mob_id);
519  ilUtil::rCopy($source_dir, $this->mobs_dir."/mm_".$a_mob_id);
520  }
521 
522  // #12930 - fullscreen
523  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
524  $mob_obj = new ilObjMediaObject($a_mob_id);
525  if ($mob_obj->hasFullscreenItem())
526  {
527  // render media object html
528  $xh = xslt_create();
529  $output = xslt_process(
530  $xh,
531  "arg:/_xml",
532  "arg:/_xsl",
533  NULL,
534  array(
535  "/_xml" =>
536  "<dummy>".
537  $mob_obj->getXML(IL_MODE_ALIAS).
538  $mob_obj->getXML(IL_MODE_OUTPUT).
539  "</dummy>",
540  "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
541  ),
542  array("mode"=>"fullscreen"));
543  xslt_free($xh);
544  unset($xh);
545 
546  // render fullscreen html
547  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
548  $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
549  $tpl->setCurrentBlock("ilMedia");
550  $tpl->setVariable("MEDIA_CONTENT", $output);
551  $output = $tpl->get();
552  unset($tpl);
553 
554  // write file
555  $file = $this->exp_dir."/fullscreen_".$a_mob_id.".html";
556  if(!($fp = @fopen($file,"w+")))
557  {
558  die("<b>Error</b>: Could not open \"".$file."\" for writing".
559  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
560  }
561  chmod($file, 0770);
562  fwrite($fp, $output);
563  fclose($fp);
564  unset($fp);
565  unset($output);
566  }
567 
568  $linked_mobs = $mob_obj->getLinkedMediaObjects();
569  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
570  }
571 
575  function exportHTMLFile($a_file_id)
576  {
577  $file_dir = $this->files_dir."/file_".$a_file_id;
578  ilUtil::makeDir($file_dir);
579 
580  include_once("./Modules/File/classes/class.ilObjFile.php");
581  $file_obj = new ilObjFile($a_file_id, false);
582  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
583  if (!is_file($source_file))
584  {
585  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
586  }
587  if (is_file($source_file))
588  {
589  copy($source_file, $file_dir."/".$file_obj->getFileName());
590  }
591  }
592 
596  function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
597  {
598  $file_dir = $this->files_dir."/file_".$a_file_id;
599  ilUtil::makeDir($file_dir);
600 
601  if (is_file($a_source_file))
602  {
603  copy($a_source_file,
604  $file_dir."/".ilUtil::getASCIIFilename($a_file_name));
605  }
606  }
607 
608 }
609 
610 ?>
xslt_create()
static getCssFilePaths()
Get css file paths.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
ILIAS Setting Class.
setContentStyleId($a_val)
Set content style id.
print $file
$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.
HTML export class for pages.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
copyPlayerFilesToTargetDirectory($a_target_dir)
Copy css files to target dir.
Skill tree.
if(strpos($jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34
xslt_free(&$proc)
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
getSyntaxStylePath()
get syntax style path
Tree handler for personal workspace.
static getLocalJavascriptFiles()
global $tpl
Definition: ilias.php:8
static _lookupType($a_obj_id)
Lookup 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 getJsFilePaths()
Get js file paths.
__construct($a_exp_dir)
Initialisation.
createDirectories()
Create directories.
getLocaljQueryPath()
Get local path of jQuery file.
getLocalMaphilightPath()
Get local path of maphilight file.
special template class to simplify handling of ITX/PEAR
Class ilObjFile.
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 _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
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
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)
global $ilUser
Definition: imgupload.php:15
Class ilObjStyleSheet.
collectPageElements($a_type, $a_id)
Collect page elements (that need to be exported separately)
const IL_MODE_OUTPUT
getLocaljQueryUIPath()
Get local path of jQuery UI file.
static getLogger($a_component_id)
Get component logger.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
exportStyles()
Export content style.
exportHTMLMOB($a_mob_id, &$a_linked_mobs)
Export media object to html.
static getWebspaceDir($mode="filesystem")
get webspace directory
exportPageElements($a_update_callback=null)
Export page elements.