ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWikiHTMLExport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $wiki_gui;
14 
21  function __construct($a_wiki_gui)
22  {
23  $this->wiki_gui = $a_wiki_gui;
24  $this->wiki = $a_wiki_gui->object;
25  }
26 
33  function buildExportFile()
34  {
35  global $ilias;
36 
37  // create export file
38  include_once("./Services/Export/classes/class.ilExport.php");
39  ilExport::_createExportDirectory($this->wiki->getId(), "html", "wiki");
40  $exp_dir =
41  ilExport::_getExportDirectory($this->wiki->getId(), "html", "wiki");
42 
43  $this->subdir = $this->wiki->getType()."_".$this->wiki->getId();
44  $this->export_dir = $exp_dir."/".$this->subdir;
45 
46  // initialize temporary target directory
47  ilUtil::delDir($this->export_dir);
48  ilUtil::makeDir($this->export_dir);
49 
50  // system style html exporter
51  include_once("./Services/Style/classes/class.ilSystemStyleHTMLExport.php");
52  $this->sys_style_html_export = new ilSystemStyleHTMLExport($this->export_dir);
53  $this->sys_style_html_export->addImage("icon_wiki_b.png");
54  $this->sys_style_html_export->export();
55 
56  // init co page html exporter
57  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
58  $this->co_page_html_export = new ilCOPageHTMLExport($this->export_dir);
59  $this->co_page_html_export->setContentStyleId(
60  $this->wiki->getStyleSheetId());
61  $this->co_page_html_export->createDirectories();
62  $this->co_page_html_export->exportStyles();
63  $this->co_page_html_export->exportSupportScripts();
64 
65  // export pages
66  $this->exportHTMLPages();
67 
68  // zip everything
69  if (true)
70  {
71  // zip it all
72  $date = time();
73  $zip_file = ilExport::_getExportDirectory($this->wiki->getId(), "html", "wiki").
74  "/".$date."__".IL_INST_ID."__".
75  $this->wiki->getType()."_".$this->wiki->getId().".zip";
76  ilUtil::zip($this->export_dir, $zip_file);
77  ilUtil::delDir($this->export_dir);
78  }
79  }
80 
84  function exportHTMLPages()
85  {
86  global $tpl, $ilBench, $ilLocator;
87 
88  $pages = ilWikiPage::getAllPages($this->wiki->getId());
89 
90  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
91  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
92  foreach ($pages as $page)
93  {
94  if (ilPageObject::_exists("wpg", $page["id"]))
95  {
96  $this->exportPageHTML($page["id"]);
97  $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
98  }
99  }
100  $this->co_page_html_export->exportPageElements();
101  }
102 
106  function exportPageHTML($a_page_id)
107  {
108  global $ilUser, $lng, $ilTabs;
109 
110  $ilTabs->clearTargets();
111 
112  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
113 
114  $this->tpl->getStandardTemplate();
115  $file = $this->export_dir."/wpg_".$a_page_id.".html";
116  // return if file is already existing
117  if (@is_file($file))
118  {
119  return;
120  }
121 
122  // page
123  include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
124  $wpg_gui = new ilWikiPageGUI($a_page_id);
125  $wpg_gui->setOutputMode("offline");
126  $wpg_gui->setPageToc($this->wiki->getPageToc());
127  $page_content = $wpg_gui->showPage();
128 
129  // export template: page content
130  $ep_tpl = new ilTemplate("tpl.export_page.html", true, true,
131  "Modules/Wiki");
132  $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
133 
134  // export template: right content
135  include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
136  $bl = new ilWikiImportantPagesBlockGUI();
137  $ep_tpl->setVariable("RIGHT_CONTENT", $bl->getHTML(true));
138 
139  // workaround
140 // $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
141  $this->tpl->setVariable("MAINMENU", "");
142 
143  $this->tpl->setTitle($this->wiki->getTitle());
144  $this->tpl->setTitleIcon("./images/icon_wiki_b.png",
145  $lng->txt("obj_wiki"));
146 
147  $this->tpl->setContent($ep_tpl->get());
148  //$this->tpl->fillMainContent();
149  $content = $this->tpl->get("DEFAULT", false, false, false,
150  true, true, true);
151 
152 //echo htmlentities($content); exit;
153  // open file
154  if (!($fp = @fopen($file,"w+")))
155  {
156  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
157  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
158  }
159 
160  // set file permissions
161  chmod($file, 0770);
162 
163  // write xml data into the file
164  fwrite($fp, $content);
165 
166  // close file
167  fclose($fp);
168 
169  if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle())
170  {
171  copy($file, $this->export_dir."/index.html");
172  }
173  }
174 
175 
176 
177 }
178 ?>