ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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;
14  const MODE_DEFAULT = "html";
15  const MODE_USER = "user_html";
16  protected $mode = self::MODE_DEFAULT;
17 
21  protected $log;
22 
29  function __construct($a_wiki)
30  {
31  $this->wiki = $a_wiki;
32  $this->log = ilLoggerFactory::getLogger('wiki');
33  }
34 
40  function setMode($a_val)
41  {
42  $this->mode = $a_val;
43  }
44 
50  function getMode()
51  {
52  return $this->mode;
53  }
54 
61  function buildExportFile()
62  {
63  $this->log->debug("buildExportFile...");
64 
65  if ($this->getMode() == self::MODE_USER)
66  {
67  global $ilDB, $ilUser;
68  include_once("./Modules/Wiki/classes/class.ilWikiUserHTMLExport.php");
69  $this->user_html_exp = new ilWikiUserHTMLExport($this->wiki, $ilDB, $ilUser);
70  }
71 
72  $ascii_name = str_replace(" ", "_", ilUtil::getASCIIFilename($this->wiki->getTitle()));
73 
74  // create export file
75  include_once("./Services/Export/classes/class.ilExport.php");
76  ilExport::_createExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
77  $exp_dir =
78  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
79 
80  if ($this->getMode() == self::MODE_USER)
81  {
82  ilUtil::delDir($exp_dir, true);
83  }
84 
85  if ($this->getMode() == self::MODE_USER)
86  {
87  $this->subdir = $ascii_name;
88  }
89  else
90  {
91  $this->subdir = $this->wiki->getType()."_".$this->wiki->getId();
92  }
93  $this->export_dir = $exp_dir."/".$this->subdir;
94 //echo "+".$this->export_dir."+";
95  // initialize temporary target directory
96  ilUtil::delDir($this->export_dir);
97  ilUtil::makeDir($this->export_dir);
98 
99  $this->log->debug("export directory: ".$this->export_dir);
100 
101  // system style html exporter
102  include_once("./Services/Style/classes/class.ilSystemStyleHTMLExport.php");
103  $this->sys_style_html_export = new ilSystemStyleHTMLExport($this->export_dir);
104  $this->sys_style_html_export->addImage("icon_wiki.svg");
105  $this->sys_style_html_export->export();
106 
107  // init co page html exporter
108  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
109  $this->co_page_html_export = new ilCOPageHTMLExport($this->export_dir);
110  $this->co_page_html_export->setContentStyleId(
111  $this->wiki->getStyleSheetId());
112  $this->co_page_html_export->createDirectories();
113  $this->co_page_html_export->exportStyles();
114  $this->co_page_html_export->exportSupportScripts();
115 
116  // export pages
117  $this->log->debug("export pages");
118  $this->exportHTMLPages();
119 
120  $date = time();
121  $zip_file_name = ($this->getMode() == self::MODE_USER)
122  ? $ascii_name.".zip"
123  : $date."__".IL_INST_ID."__".$this->wiki->getType()."_".$this->wiki->getId().".zip";
124 
125  // zip everything
126  if (true)
127  {
128  // zip it all
129  $zip_file = ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki").
130  "/".$zip_file_name;
131  $this->log->debug("zip: ".$zip_file);
132  ilUtil::zip($this->export_dir, $zip_file);
133  ilUtil::delDir($this->export_dir);
134  }
135  }
136 
140  function exportHTMLPages()
141  {
142  global $tpl, $ilBench, $ilLocator;
143 
144  $pages = ilWikiPage::getAllPages($this->wiki->getId());
145 
146  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
147  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
148  $cnt = 0;
149  foreach ($pages as $page)
150  {
151  $this->log->debug("page: ".$page["id"]);
152  if (ilWikiPage::_exists("wpg", $page["id"]))
153  {
154  $this->log->debug("export page");
155  $this->exportPageHTML($page["id"]);
156  $this->log->debug("collect page elements");
157  $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
158  }
159 //sleep(2);
160  if ($this->getMode() == self::MODE_USER)
161  {
162  $cnt++;
163  $this->log->debug("update status: ".$cnt);
164  $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt) ,ilWikiUserHTMLExport::RUNNING);
165  }
166 
167  }
168  $this->co_page_html_export->exportPageElements($this->updateUserHTMLStatusForPageElements);
169  }
170 
176  function updateUserHTMLStatusForPageElements($a_total, $a_cnt)
177  {
178  if ($this->getMode() == self::MODE_USER)
179  {
180  $this->user_html_exp->updateStatus((int) 50 + (50 / count($a_total) * $a_cnt) ,ilWikiUserHTMLExport::RUNNING);
181  }
182  }
183 
184 
188  function exportPageHTML($a_page_id)
189  {
190  global $ilUser, $lng, $ilTabs;
191 
192  $ilTabs->clearTargets();
193 
194  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
195 
196  $this->tpl->getStandardTemplate();
197  $file = $this->export_dir."/wpg_".$a_page_id.".html";
198  // return if file is already existing
199  if (@is_file($file))
200  {
201  $this->log->debug("file already exists");
202  return;
203  }
204 
205  // page
206  $this->log->debug("init page gui");
207  include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
208  $wpg_gui = new ilWikiPageGUI($a_page_id);
209  $wpg_gui->setOutputMode("offline");
210  $page_content = $wpg_gui->showPage();
211 
212  // export template: page content
213  $this->log->debug("init page gui");
214  $ep_tpl = new ilTemplate("tpl.export_page.html", true, true,
215  "Modules/Wiki");
216  $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
217 
218  // export template: right content
219  include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
220  $bl = new ilWikiImportantPagesBlockGUI();
221  $ep_tpl->setVariable("RIGHT_CONTENT", $bl->getHTML(true));
222 
223  // workaround
224 // $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
225  $this->tpl->setVariable("MAINMENU", "");
226 
227  $this->log->debug("set title");
228  $this->tpl->setTitle($this->wiki->getTitle());
229  $this->tpl->setTitleIcon("./images/icon_wiki.svg",
230  $lng->txt("obj_wiki"));
231 
232  $this->tpl->setContent($ep_tpl->get());
233  //$this->tpl->fillMainContent();
234  $content = $this->tpl->get("DEFAULT", false, false, false,
235  true, true, true);
236 
237 //echo htmlentities($content); exit;
238  // open file
239  $this->log->debug("write file: ".$file);
240  if (!($fp = @fopen($file,"w+")))
241  {
242  $this->log->error("Could not open ".$file." for writing.");
243  include_once("./Modules/Wiki/exceptions/class.ilWikiExportException.php");
244  throw new ilWikiExportException("Could not open \"".$file."\" for writing.");
245  }
246 
247  // set file permissions
248  $this->log->debug("set permissions");
249  chmod($file, 0770);
250 
251  // write xml data into the file
252  fwrite($fp, $content);
253 
254  // close file
255  fclose($fp);
256 
257  if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle())
258  {
259  copy($file, $this->export_dir."/index.html");
260  }
261  }
262 
269  function getUserExportFile()
270  {
271  include_once("./Services/Export/classes/class.ilExport.php");
272  $exp_dir =
273  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
274  $this->log->debug("dir: ".$exp_dir);
275  foreach (new DirectoryIterator($exp_dir) as $fileInfo)
276  {
277  $this->log->debug("file: ".$fileInfo->getFilename());
278  if (pathinfo($fileInfo->getFilename(),PATHINFO_EXTENSION) == "zip")
279  {
280  $this->log->debug("return: ".$exp_dir."/".$fileInfo->getFilename());
281  return $exp_dir."/".$fileInfo->getFilename();
282  }
283  }
284  return false;
285  }
286 
287 
288 }
289 ?>
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
print $file
__construct($a_wiki)
Constructor.
Base exception class for wikis.
getUserExportFile()
Get user export file.
HTML export class for pages.
exportHTMLPages()
Export all pages.
HTML export class for system styles.
_createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
Create export directory.
updateUserHTMLStatusForPageElements($a_total, $a_cnt)
Callback for updating the export status during elements export (media objects, files, ...)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
global $tpl
Definition: ilias.php:8
Class manages user html export.
special template class to simplify handling of ITX/PEAR
Class ilWikiPage GUI class.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
setMode($a_val)
Set mode.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
exportPageHTML($a_page_id)
Export page html.
buildExportFile()
Build export file.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
global $ilBench
Definition: ilias.php:18
global $ilDB
Wiki HTML exporter class.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static getLogger($a_component_id)
Get component logger.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getAllPages($a_wiki_id)
Get all pages of wiki.