ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilWikiHTMLExport Class Reference

Wiki HTML exporter class. More...

+ Collaboration diagram for ilWikiHTMLExport:

Public Member Functions

 __construct ($a_wiki)
 Constructor. More...
 
 setMode ($a_val)
 Set mode. More...
 
 getMode ()
 Get mode. More...
 
 buildExportFile ()
 Build export file. More...
 
 exportHTMLPages ()
 Export all pages. More...
 
 updateUserHTMLStatusForPageElements ($a_total, $a_cnt)
 Callback for updating the export status during elements export (media objects, files, ...) More...
 
 exportPageHTML ($a_page_id)
 Export page html. More...
 
 getUserExportFile ()
 Get user export file. More...
 

Data Fields

const MODE_DEFAULT = "html"
 
const MODE_USER = "user_html"
 

Protected Attributes

 $db
 
 $user
 
 $lng
 
 $tabs
 
 $wiki
 
 $mode = self::MODE_DEFAULT
 
 $log
 

Detailed Description

Wiki HTML exporter class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$ /

Definition at line 11 of file class.ilWikiHTMLExport.php.

Constructor & Destructor Documentation

◆ __construct()

ilWikiHTMLExport::__construct (   $a_wiki)

Constructor.

Parameters

Definition at line 49 of file class.ilWikiHTMLExport.php.

References $DIC, ilLoggerFactory\getLogger(), and user().

50  {
51  global $DIC;
52 
53  $this->db = $DIC->database();
54  $this->user = $DIC->user();
55  $this->lng = $DIC->language();
56  $this->tabs = $DIC->tabs();
57  $this->wiki = $a_wiki;
58  $this->log = ilLoggerFactory::getLogger('wiki');
59  }
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildExportFile()

ilWikiHTMLExport::buildExportFile ( )

Build export file.

Parameters

Definition at line 87 of file class.ilWikiHTMLExport.php.

References $db, $ilDB, $ilUser, $user, ilExport\_createExportDirectory(), ilExport\_getExportDirectory(), ilUtil\delDir(), exportHTMLPages(), ilUtil\getASCIIFilename(), ilObjStyleSheet\getEffectiveContentStyleId(), ilMathJax\getInstance(), getMode(), ilUtil\makeDir(), ilMathJax\PURPOSE_EXPORT, time, and ilUtil\zip().

88  {
89  $this->log->debug("buildExportFile...");
90  //init the mathjax rendering for HTML export
91  include_once './Services/MathJax/classes/class.ilMathJax.php';
93 
94  if ($this->getMode() == self::MODE_USER) {
95  $ilDB = $this->db;
97  include_once("./Modules/Wiki/classes/class.ilWikiUserHTMLExport.php");
98  $this->user_html_exp = new ilWikiUserHTMLExport($this->wiki, $ilDB, $ilUser);
99  }
100 
101  $ascii_name = str_replace(" ", "_", ilUtil::getASCIIFilename($this->wiki->getTitle()));
102 
103  // create export file
104  include_once("./Services/Export/classes/class.ilExport.php");
105  ilExport::_createExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
106  $exp_dir =
107  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
108 
109  if ($this->getMode() == self::MODE_USER) {
110  ilUtil::delDir($exp_dir, true);
111  }
112 
113  if ($this->getMode() == self::MODE_USER) {
114  $this->subdir = $ascii_name;
115  } else {
116  $this->subdir = $this->wiki->getType() . "_" . $this->wiki->getId();
117  }
118  $this->export_dir = $exp_dir . "/" . $this->subdir;
119  //echo "+".$this->export_dir."+";
120  // initialize temporary target directory
121  ilUtil::delDir($this->export_dir);
122  ilUtil::makeDir($this->export_dir);
123 
124  $this->log->debug("export directory: " . $this->export_dir);
125 
126  // system style html exporter
127  include_once("./Services/Style/System/classes/class.ilSystemStyleHTMLExport.php");
128  $this->sys_style_html_export = new ilSystemStyleHTMLExport($this->export_dir);
129  $this->sys_style_html_export->addImage("icon_wiki.svg");
130  $this->sys_style_html_export->export();
131 
132  // init co page html exporter
133  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
134  $this->co_page_html_export = new ilCOPageHTMLExport($this->export_dir);
135  $this->co_page_html_export->setContentStyleId(
137  $this->wiki->getStyleSheetId(),
138  $this->wiki->getType()
139  )
140  );
141  $this->co_page_html_export->createDirectories();
142  $this->co_page_html_export->exportStyles();
143  $this->co_page_html_export->exportSupportScripts();
144 
145  // export pages
146  $this->log->debug("export pages");
147  $this->exportHTMLPages();
148 
149  $date = time();
150  $zip_file_name = ($this->getMode() == self::MODE_USER)
151  ? $ascii_name . ".zip"
152  : $date . "__" . IL_INST_ID . "__" . $this->wiki->getType() . "_" . $this->wiki->getId() . ".zip";
153 
154  // zip everything
155  if (true) {
156  // zip it all
157  $zip_file = ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki") .
158  "/" . $zip_file_name;
159  $this->log->debug("zip: " . $zip_file);
160  ilUtil::zip($this->export_dir, $zip_file);
161  ilUtil::delDir($this->export_dir);
162  }
163  }
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
HTML export class for pages.
exportHTMLPages()
Export all pages.
HTML export class for system styles.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
Class manages user html export.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
$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 makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getInstance()
Singleton: get instance.
global $ilDB
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

◆ exportHTMLPages()

ilWikiHTMLExport::exportHTMLPages ( )

Export all pages.

Definition at line 168 of file class.ilWikiHTMLExport.php.

References ilPageObject\_exists(), exportPageHTML(), ilWikiPage\getAllWikiPages(), getMode(), ilWikiUserHTMLExport\RUNNING, and updateUserHTMLStatusForPageElements().

Referenced by buildExportFile().

169  {
170  $pages = ilWikiPage::getAllWikiPages($this->wiki->getId());
171 
172  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
173  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
174  $cnt = 0;
175  foreach ($pages as $page) {
176  $this->log->debug("page: " . $page["id"]);
177  if (ilWikiPage::_exists("wpg", $page["id"])) {
178  $this->log->debug("export page");
179  $this->exportPageHTML($page["id"]);
180  $this->log->debug("collect page elements");
181  $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
182  }
183 
184  if ($this->getMode() == self::MODE_USER) {
185  $cnt++;
186  $this->log->debug("update status: " . $cnt);
187  $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt), ilWikiUserHTMLExport::RUNNING);
188  }
189  }
190  $this->co_page_html_export->exportPageElements($this->updateUserHTMLStatusForPageElements);
191  }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
updateUserHTMLStatusForPageElements($a_total, $a_cnt)
Callback for updating the export status during elements export (media objects, files, ...)
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
exportPageHTML($a_page_id)
Export page html.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportPageHTML()

ilWikiHTMLExport::exportPageHTML (   $a_page_id)

Export page html.

Definition at line 209 of file class.ilWikiHTMLExport.php.

References $file, $ilUser, $lng, $tabs, and $user.

Referenced by exportHTMLPages().

210  {
212  $lng = $this->lng;
213  $ilTabs = $this->tabs;
214 
215  $ilTabs->clearTargets();
216 
217  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
218 
219  $this->tpl->getStandardTemplate();
220  $file = $this->export_dir . "/wpg_" . $a_page_id . ".html";
221  // return if file is already existing
222  if (@is_file($file)) {
223  $this->log->debug("file already exists");
224  return;
225  }
226 
227  // page
228  $this->log->debug("init page gui");
229  include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
230  $wpg_gui = new ilWikiPageGUI($a_page_id);
231  $wpg_gui->setOutputMode("offline");
232  $page_content = $wpg_gui->showPage();
233 
234  // export template: page content
235  $this->log->debug("init page gui");
236  $ep_tpl = new ilTemplate(
237  "tpl.export_page.html",
238  true,
239  true,
240  "Modules/Wiki"
241  );
242  $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
243 
244  // export template: right content
245  include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
246  $bl = new ilWikiImportantPagesBlockGUI();
247  $ep_tpl->setVariable("RIGHT_CONTENT", $bl->getHTML(true));
248 
249  // workaround
250  // $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
251  $this->tpl->setVariable("MAINMENU", "");
252 
253  $this->log->debug("set title");
254  $this->tpl->setTitle($this->wiki->getTitle());
255  $this->tpl->setTitleIcon(
256  "./images/icon_wiki.svg",
257  $lng->txt("obj_wiki")
258  );
259 
260  $this->tpl->setContent($ep_tpl->get());
261  //$this->tpl->fillMainContent();
262  $content = $this->tpl->get(
263  "DEFAULT",
264  false,
265  false,
266  false,
267  true,
268  true,
269  true
270  );
271 
272  //echo htmlentities($content); exit;
273  // open file
274  $this->log->debug("write file: " . $file);
275  if (!($fp = @fopen($file, "w+"))) {
276  $this->log->error("Could not open " . $file . " for writing.");
277  include_once("./Modules/Wiki/exceptions/class.ilWikiExportException.php");
278  throw new ilWikiExportException("Could not open \"" . $file . "\" for writing.");
279  }
280 
281  // set file permissions
282  $this->log->debug("set permissions");
283  chmod($file, 0770);
284 
285  // write xml data into the file
286  fwrite($fp, $content);
287 
288  // close file
289  fclose($fp);
290 
291  if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle()) {
292  copy($file, $this->export_dir . "/index.html");
293  }
294  }
Base exception class for wikis.
special template class to simplify handling of ITX/PEAR
Class ilWikiPage GUI class.
$ilUser
Definition: imgupload.php:18
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the caller graph for this function:

◆ getMode()

ilWikiHTMLExport::getMode ( )

Get mode.

Returns
int MODE_DEFAULT|MODE_USER

Definition at line 76 of file class.ilWikiHTMLExport.php.

References $mode.

Referenced by buildExportFile(), exportHTMLPages(), getUserExportFile(), and updateUserHTMLStatusForPageElements().

77  {
78  return $this->mode;
79  }
+ Here is the caller graph for this function:

◆ getUserExportFile()

ilWikiHTMLExport::getUserExportFile ( )

Get user export file.

Parameters

Definition at line 302 of file class.ilWikiHTMLExport.php.

References ilExport\_getExportDirectory(), and getMode().

303  {
304  include_once("./Services/Export/classes/class.ilExport.php");
305  $exp_dir =
306  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
307  $this->log->debug("dir: " . $exp_dir);
308  foreach (new DirectoryIterator($exp_dir) as $fileInfo) {
309  $this->log->debug("file: " . $fileInfo->getFilename());
310  if (pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION) == "zip") {
311  $this->log->debug("return: " . $exp_dir . "/" . $fileInfo->getFilename());
312  return $exp_dir . "/" . $fileInfo->getFilename();
313  }
314  }
315  return false;
316  }
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
+ Here is the call graph for this function:

◆ setMode()

ilWikiHTMLExport::setMode (   $a_val)

Set mode.

Parameters
int$a_valMODE_DEFAULT|MODE_USER

Definition at line 66 of file class.ilWikiHTMLExport.php.

67  {
68  $this->mode = $a_val;
69  }

◆ updateUserHTMLStatusForPageElements()

ilWikiHTMLExport::updateUserHTMLStatusForPageElements (   $a_total,
  $a_cnt 
)

Callback for updating the export status during elements export (media objects, files, ...)

Parameters

Definition at line 198 of file class.ilWikiHTMLExport.php.

References getMode(), and ilWikiUserHTMLExport\RUNNING.

Referenced by exportHTMLPages().

199  {
200  if ($this->getMode() == self::MODE_USER) {
201  $this->user_html_exp->updateStatus((int) 50 + (50 / count($a_total) * $a_cnt), ilWikiUserHTMLExport::RUNNING);
202  }
203  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilWikiHTMLExport::$db
protected

Definition at line 16 of file class.ilWikiHTMLExport.php.

Referenced by buildExportFile().

◆ $lng

ilWikiHTMLExport::$lng
protected

Definition at line 26 of file class.ilWikiHTMLExport.php.

Referenced by exportPageHTML().

◆ $log

ilWikiHTMLExport::$log
protected

Definition at line 41 of file class.ilWikiHTMLExport.php.

◆ $mode

ilWikiHTMLExport::$mode = self::MODE_DEFAULT
protected

Definition at line 36 of file class.ilWikiHTMLExport.php.

Referenced by getMode().

◆ $tabs

ilWikiHTMLExport::$tabs
protected

Definition at line 31 of file class.ilWikiHTMLExport.php.

Referenced by exportPageHTML().

◆ $user

ilWikiHTMLExport::$user
protected

Definition at line 21 of file class.ilWikiHTMLExport.php.

Referenced by buildExportFile(), and exportPageHTML().

◆ $wiki

ilWikiHTMLExport::$wiki
protected

Definition at line 33 of file class.ilWikiHTMLExport.php.

◆ MODE_DEFAULT

const ilWikiHTMLExport::MODE_DEFAULT = "html"

Definition at line 34 of file class.ilWikiHTMLExport.php.

◆ MODE_USER

const ilWikiHTMLExport::MODE_USER = "user_html"

The documentation for this class was generated from the following file: