ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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 
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 // copy(ilPlayerUtil::getLocalMediaElementCssPath(),
178 // $this->css_dir.'/mediaelementplayer.css');
179 // copy(ilPlayerUtil::getLocalMediaElementJsPath(),
180 // $this->js_dir.'/mediaelement-and-player.js');
181  }
182 
189  function getPreparedMainTemplate($a_tpl = "")
190  {
191  global $ilUser;
192 
193  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
194 
195  if ($a_tpl != "")
196  {
197  $tpl = $a_tpl;
198  }
199  else
200  {
201  // template workaround: reset of template
202  $tpl = new ilTemplate("tpl.main.html", true, true);
203  }
204 
205  // scripts needed
206  $scripts = array("./js/yahoo/yahoo-min.js", "./js/yahoo/yahoo-dom-event.js",
207  "./js/yahoo/animation-min.js", "./js/yahoo/container-min.js",
208  "./js/Basic.js", "./js/jquery.js", "./js/jquery-ui-min.js",
209  "./js/ilOverlay.js", "./js/accordion.js", "./js/ilCOPagePres.js",
210  "./js/ilTooltip.js", "./js/maphilight.js");
211  $scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
212 
213  $mathJaxSetting = new ilSetting("MathJax");
214  $use_mathjax = $mathJaxSetting->get("enable");
215  if ($use_mathjax)
216  {
217  $scripts[] = $mathJaxSetting->get("path_to_mathjax");
218  }
219 
220  foreach ($scripts as $script)
221  {
222  $tpl->setCurrentBlock("js_file");
223  $tpl->setVariable("JS_FILE", $script);
224  $tpl->parseCurrentBlock();
225  }
226 
227  // css files needed
228  $style_name = $ilUser->prefs["style"].".css";
229  $css_files = array("./css/accordion.css", "./css/container.css",
230  "./content_style/content.css", "./style/".$style_name);
231  $css_files = array_merge($css_files, ilPlayerUtil::getCssFilePaths());
232 
233  foreach ($css_files as $css)
234  {
235  $tpl->setCurrentBlock("css_file");
236  $tpl->setVariable("CSS_FILE", $css);
237  $tpl->parseCurrentBlock();
238  }
239 
240  return $tpl;
241  }
242 
249  function collectPageElements($a_type, $a_id)
250  {
251  // collect media objects
252  $pg_mobs = ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
253  foreach($pg_mobs as $pg_mob)
254  {
255  $this->mobs[$pg_mob] = $pg_mob;
256  }
257 
258  // collect all files
259  include_once("./Modules/File/classes/class.ilObjFile.php");
260  $files = ilObjFile::_getFilesOfObject($a_type, $a_id);
261  foreach($files as $f)
262  {
263  $this->files[$f] = $f;
264  }
265 
266 
267  $skill_tree = $ws_tree = null;
268 
269  $pcs = ilPageContentUsage::getUsagesOfPage($a_id, $a_type);
270  foreach ($pcs as $pc)
271  {
272  // skils
273  if ($pc["type"] == "skmg")
274  {
275  $skill_id = $pc["id"];
276 
277  // trying to find user id
278  $user_id = null;
279  switch($a_type)
280  {
281  case "prtf:pg":
282  include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
283  $page = new ilPortfolioPage($a_id);
284  $user_id = $page->create_user;
285  break;
286 
287  default:
288  // :TODO:
289  break;
290  }
291 
292  if($user_id)
293  {
294  // we only need 1 instance each
295  if(!$skill_tree)
296  {
297  include_once "Services/Skill/classes/class.ilSkillTree.php";
298  $skill_tree = new ilSkillTree();
299 
300  include_once "Services/Skill/classes/class.ilPersonalSkill.php";
301 
302  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
303  $ws_tree = new ilWorkspaceTree($user_id);
304  }
305 
306  // walk skill tree
307  include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
308  $vtree = new ilVirtualSkillTree();
309  $tref_id = 0;
310  $skill_id = (int) $skill_id;
311  if (ilSkillTreeNode::_lookupType($skill_id) == "sktr")
312  {
313  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
314  $tref_id = $skill_id;
315  $skill_id = ilSkillTemplateReference::_lookupTemplateId($skill_id);
316  }
317  $b_skills = $vtree->getSubTreeForCSkillId($skill_id.":".$tref_id, true);
318 
319  foreach ($b_skills as $bs)
320  {
321  $skill = ilSkillTreeNodeFactory::getInstance($bs["skill_id"]);
322  $level_data = $skill->getLevelData();
323  foreach ($level_data as $k => $v)
324  {
325  // get assigned materials from personal skill
326  $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref_id"], $v["id"]);
327  if(sizeof($mat))
328  {
329  foreach($mat as $item)
330  {
331  $wsp_id = $item["wsp_id"];
332  $obj_id = $ws_tree->lookupObjectId($wsp_id);
333 
334  // all possible material types for now
335  switch(ilObject::_lookupType($obj_id))
336  {
337  case "file":
338  $this->files[$obj_id] = $obj_id;
339  break;
340 
341  case "tstv":
342  include_once "Modules/Test/classes/class.ilObjTestVerification.php";
343  $obj = new ilObjTestVerification($obj_id, false);
344  $this->files_direct[$obj_id] = array($obj->getFilePath(),
345  $obj->getOfflineFilename());
346  break;
347 
348  case "excv":
349  include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
350  $obj = new ilObjExerciseVerification($obj_id, false);
351  $this->files_direct[$obj_id] = array($obj->getFilePath(),
352  $obj->getOfflineFilename());
353  break;
354 
355  case "crsv":
356  include_once "Modules/Course/classes/Verification/class.ilObjCourseVerification.php";
357  $obj = new ilObjCourseVerification($obj_id, false);
358  $this->files_direct[$obj_id] = array($obj->getFilePath(),
359  $obj->getOfflineFilename());
360  break;
361 
362  case "scov":
363  include_once "Modules/ScormAicc/classes/Verification/class.ilObjSCORMVerification.php";
364  $obj = new ilObjSCORMVerification($obj_id, false);
365  $this->files_direct[$obj_id] = array($obj->getFilePath(),
366  $obj->getOfflineFilename());
367  break;
368  }
369  }
370  }
371  }
372  }
373  }
374  }
375  }
376 
377  }
378 
386  {
387  // export all media objects
388  $linked_mobs = array();
389  foreach ($this->mobs as $mob)
390  {
391  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
392  {
393  $this->exportHTMLMOB($mob, $linked_mobs);
394  }
395  }
396  $linked_mobs2 = array(); // mobs linked in link areas
397  foreach ($linked_mobs as $mob)
398  {
399  if (ilObject::_exists($mob))
400  {
401  $this->exportHTMLMOB($mob, $linked_mobs2);
402  }
403  }
404 
405  // export all file objects
406  foreach ($this->files as $file)
407  {
408  $this->exportHTMLFile($file);
409  }
410 
411  // export all files (which are not objects
412  foreach ($this->files_direct as $file_id => $attr)
413  {
414  $this->exportHTMLFileDirect($file_id, $attr[0], $attr[1]);
415  }
416  }
417 
421  function exportHTMLMOB($a_mob_id, &$a_linked_mobs)
422  {
423  global $tpl;
424 
425  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
426  if (@is_dir($source_dir))
427  {
428  ilUtil::makeDir($this->mobs_dir."/mm_".$a_mob_id);
429  ilUtil::rCopy($source_dir, $this->mobs_dir."/mm_".$a_mob_id);
430  }
431 
432  // #12930 - fullscreen
433  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
434  $mob_obj = new ilObjMediaObject($a_mob_id);
435  if ($mob_obj->hasFullscreenItem())
436  {
437  // render media object html
438  $xh = xslt_create();
439  $output = xslt_process(
440  $xh,
441  "arg:/_xml",
442  "arg:/_xsl",
443  NULL,
444  array(
445  "/_xml" =>
446  "<dummy>".
447  $mob_obj->getXML(IL_MODE_ALIAS).
448  $mob_obj->getXML(IL_MODE_OUTPUT).
449  "</dummy>",
450  "/_xsl" => file_get_contents("./Services/COPage/xsl/page.xsl")
451  ),
452  array("mode"=>"fullscreen"));
453  xslt_free($xh);
454  unset($xh);
455 
456  // render fullscreen html
457  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
458  $tpl = $this->getPreparedMainTemplate($tpl); // adds js/css
459  $tpl->setCurrentBlock("ilMedia");
460  $tpl->setVariable("MEDIA_CONTENT", $output);
461  $output = $tpl->get();
462  unset($tpl);
463 
464  // write file
465  $file = $this->exp_dir."/fullscreen_".$a_mob_id.".html";
466  if(!($fp = @fopen($file,"w+")))
467  {
468  die("<b>Error</b>: Could not open \"".$file."\" for writing".
469  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
470  }
471  chmod($file, 0770);
472  fwrite($fp, $output);
473  fclose($fp);
474  unset($fp);
475  unset($output);
476  }
477 
478  $linked_mobs = $mob_obj->getLinkedMediaObjects();
479  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
480  }
481 
485  function exportHTMLFile($a_file_id)
486  {
487  $file_dir = $this->files_dir."/file_".$a_file_id;
488  ilUtil::makeDir($file_dir);
489 
490  include_once("./Modules/File/classes/class.ilObjFile.php");
491  $file_obj = new ilObjFile($a_file_id, false);
492  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
493  if (!is_file($source_file))
494  {
495  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
496  }
497  if (is_file($source_file))
498  {
499  copy($source_file, $file_dir."/".$file_obj->getFileName());
500  }
501  }
502 
506  function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
507  {
508  $file_dir = $this->files_dir."/file_".$a_file_id;
509  ilUtil::makeDir($file_dir);
510 
511  if (is_file($a_source_file))
512  {
513  copy($a_source_file,
514  $file_dir."/".ilUtil::getASCIIFilename($a_file_name));
515  }
516  }
517 
518 }
519 
520 ?>
xslt_create()
static getCssFilePaths()
Get css file paths.
ILIAS Setting Class.
setContentStyleId($a_val)
Set content style id.
print $file
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.
xslt_free(&$proc)
getContentStyleId()
Get content style id.
exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name)
Export file from path.
exportPageElements()
Export page elements.
getPreparedMainTemplate($a_tpl="")
Get prepared main template.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
_getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
getSyntaxStylePath()
get syntax style path
Tree handler for personal workspace.
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.
$GLOBALS['ct_recipient']
xslt_process(&$proc, $xml_var, $xslt_var, $dummy, $args, $params, $a_no_warnings=false)
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.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
static _lookupTemplateId($a_obj_id)
Lookup template ID.
Class ilObjMediaObject.
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.
exportStyles()
Export content style.
if(strpos($jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34
exportHTMLMOB($a_mob_id, &$a_linked_mobs)
Export media object to html.
static getWebspaceDir($mode="filesystem")
get webspace directory