ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  //init the mathjax rendering for HTML export
65  include_once './Services/MathJax/classes/class.ilMathJax.php';
67 
68  if ($this->getMode() == self::MODE_USER)
69  {
70  global $ilDB, $ilUser;
71  include_once("./Modules/Wiki/classes/class.ilWikiUserHTMLExport.php");
72  $this->user_html_exp = new ilWikiUserHTMLExport($this->wiki, $ilDB, $ilUser);
73  }
74 
75  $ascii_name = str_replace(" ", "_", ilUtil::getASCIIFilename($this->wiki->getTitle()));
76 
77  // create export file
78  include_once("./Services/Export/classes/class.ilExport.php");
79  ilExport::_createExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
80  $exp_dir =
81  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
82 
83  if ($this->getMode() == self::MODE_USER)
84  {
85  ilUtil::delDir($exp_dir, true);
86  }
87 
88  if ($this->getMode() == self::MODE_USER)
89  {
90  $this->subdir = $ascii_name;
91  }
92  else
93  {
94  $this->subdir = $this->wiki->getType()."_".$this->wiki->getId();
95  }
96  $this->export_dir = $exp_dir."/".$this->subdir;
97 //echo "+".$this->export_dir."+";
98  // initialize temporary target directory
99  ilUtil::delDir($this->export_dir);
100  ilUtil::makeDir($this->export_dir);
101 
102  $this->log->debug("export directory: ".$this->export_dir);
103 
104  // system style html exporter
105  include_once("./Services/Style/System/classes/class.ilSystemStyleHTMLExport.php");
106  $this->sys_style_html_export = new ilSystemStyleHTMLExport($this->export_dir);
107  $this->sys_style_html_export->addImage("icon_wiki.svg");
108  $this->sys_style_html_export->export();
109 
110  // init co page html exporter
111  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
112  $this->co_page_html_export = new ilCOPageHTMLExport($this->export_dir);
113  $this->co_page_html_export->setContentStyleId(
114  $this->wiki->getStyleSheetId());
115  $this->co_page_html_export->createDirectories();
116  $this->co_page_html_export->exportStyles();
117  $this->co_page_html_export->exportSupportScripts();
118 
119  // export pages
120  $this->log->debug("export pages");
121  $this->exportHTMLPages();
122 
123  $date = time();
124  $zip_file_name = ($this->getMode() == self::MODE_USER)
125  ? $ascii_name.".zip"
126  : $date."__".IL_INST_ID."__".$this->wiki->getType()."_".$this->wiki->getId().".zip";
127 
128  // zip everything
129  if (true)
130  {
131  // zip it all
132  $zip_file = ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki").
133  "/".$zip_file_name;
134  $this->log->debug("zip: ".$zip_file);
135  ilUtil::zip($this->export_dir, $zip_file);
136  ilUtil::delDir($this->export_dir);
137  }
138  }
139 
143  function exportHTMLPages()
144  {
145  global $tpl, $ilBench, $ilLocator;
146 
147  $pages = ilWikiPage::getAllWikiPages($this->wiki->getId());
148 
149  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
150  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
151  $cnt = 0;
152  foreach ($pages as $page)
153  {
154  $this->log->debug("page: ".$page["id"]);
155  if (ilWikiPage::_exists("wpg", $page["id"]))
156  {
157  $this->log->debug("export page");
158  $this->exportPageHTML($page["id"]);
159  $this->log->debug("collect page elements");
160  $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
161  }
162 //sleep(2);
163  if ($this->getMode() == self::MODE_USER)
164  {
165  $cnt++;
166  $this->log->debug("update status: ".$cnt);
167  $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt) ,ilWikiUserHTMLExport::RUNNING);
168  }
169 
170  }
171  $this->co_page_html_export->exportPageElements($this->updateUserHTMLStatusForPageElements);
172  }
173 
179  function updateUserHTMLStatusForPageElements($a_total, $a_cnt)
180  {
181  if ($this->getMode() == self::MODE_USER)
182  {
183  $this->user_html_exp->updateStatus((int) 50 + (50 / count($a_total) * $a_cnt) ,ilWikiUserHTMLExport::RUNNING);
184  }
185  }
186 
187 
191  function exportPageHTML($a_page_id)
192  {
193  global $ilUser, $lng, $ilTabs;
194 
195  $ilTabs->clearTargets();
196 
197  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
198 
199  $this->tpl->getStandardTemplate();
200  $file = $this->export_dir."/wpg_".$a_page_id.".html";
201  // return if file is already existing
202  if (@is_file($file))
203  {
204  $this->log->debug("file already exists");
205  return;
206  }
207 
208  // page
209  $this->log->debug("init page gui");
210  include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
211  $wpg_gui = new ilWikiPageGUI($a_page_id);
212  $wpg_gui->setOutputMode("offline");
213  $page_content = $wpg_gui->showPage();
214 
215  // export template: page content
216  $this->log->debug("init page gui");
217  $ep_tpl = new ilTemplate("tpl.export_page.html", true, true,
218  "Modules/Wiki");
219  $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
220 
221  // export template: right content
222  include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
223  $bl = new ilWikiImportantPagesBlockGUI();
224  $ep_tpl->setVariable("RIGHT_CONTENT", $bl->getHTML(true));
225 
226  // workaround
227 // $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
228  $this->tpl->setVariable("MAINMENU", "");
229 
230  $this->log->debug("set title");
231  $this->tpl->setTitle($this->wiki->getTitle());
232  $this->tpl->setTitleIcon("./images/icon_wiki.svg",
233  $lng->txt("obj_wiki"));
234 
235  $this->tpl->setContent($ep_tpl->get());
236  //$this->tpl->fillMainContent();
237  $content = $this->tpl->get("DEFAULT", false, false, false,
238  true, true, true);
239 
240 //echo htmlentities($content); exit;
241  // open file
242  $this->log->debug("write file: ".$file);
243  if (!($fp = @fopen($file,"w+")))
244  {
245  $this->log->error("Could not open ".$file." for writing.");
246  include_once("./Modules/Wiki/exceptions/class.ilWikiExportException.php");
247  throw new ilWikiExportException("Could not open \"".$file."\" for writing.");
248  }
249 
250  // set file permissions
251  $this->log->debug("set permissions");
252  chmod($file, 0770);
253 
254  // write xml data into the file
255  fwrite($fp, $content);
256 
257  // close file
258  fclose($fp);
259 
260  if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle())
261  {
262  copy($file, $this->export_dir."/index.html");
263  }
264  }
265 
272  function getUserExportFile()
273  {
274  include_once("./Services/Export/classes/class.ilExport.php");
275  $exp_dir =
276  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
277  $this->log->debug("dir: ".$exp_dir);
278  foreach (new DirectoryIterator($exp_dir) as $fileInfo)
279  {
280  $this->log->debug("file: ".$fileInfo->getFilename());
281  if (pathinfo($fileInfo->getFilename(),PATHINFO_EXTENSION) == "zip")
282  {
283  $this->log->debug("return: ".$exp_dir."/".$fileInfo->getFilename());
284  return $exp_dir."/".$fileInfo->getFilename();
285  }
286  }
287  return false;
288  }
289 
290 
291 }
292 ?>
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
__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.
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.
$ilUser
Definition: imgupload.php:18
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
const PURPOSE_EXPORT
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
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.
static getInstance()
Singleton: get instance.
global $lng
Definition: privfeed.php:17
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively