ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
class.ilPortfolioHTMLExport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  protected $portfolio_gui;
15 
22  function __construct($a_portfolio_gui, $a_object)
23  {
24  $this->portfolio_gui = $a_portfolio_gui;
25  $this->object = $a_object;
26  }
27 
34  function buildExportFile()
35  {
36  global $ilias;
37 
38  // create export file
39  include_once("./Services/Export/classes/class.ilExport.php");
40  ilExport::_createExportDirectory($this->object->getId(), "html", "prtf");
41  $exp_dir = ilExport::_getExportDirectory($this->object->getId(), "html", "prtf");
42 
43  $this->subdir = $this->object->getType()."_".$this->object->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_prtf.svg");
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($this->object->getStyleSheetId());
60  $this->co_page_html_export->createDirectories();
61  $this->co_page_html_export->exportStyles();
62  $this->co_page_html_export->exportSupportScripts();
63 
64  // banner
65  $prfa_set = new ilSetting("prfa");
66  if($prfa_set->get("banner"))
67  {
68  $banner = $this->object->getImageFullPath();
69  if($banner) // #16096
70  {
71  copy($banner, $this->export_dir."/".basename($banner));
72  }
73  }
74  // page element: profile picture
75  $ppic = ilObjUser::_getPersonalPicturePath($this->object->getOwner(), "big", true, true);
76  if($ppic)
77  {
78  $ppic = array_shift(explode("?", $ppic));
79  copy($ppic, $this->export_dir."/".basename($ppic));
80  }
81  // header image: profile picture
82  $ppic = ilObjUser::_getPersonalPicturePath($this->object->getOwner(), "xsmall", true, true);
83  if($ppic)
84  {
85  $ppic = array_shift(explode("?", $ppic));
86  copy($ppic, $this->export_dir."/".basename($ppic));
87  }
88 
89  // export pages
90  $this->exportHTMLPages();
91 
92  // add js/images/file to zip
93  $images = $files = $js_files = array();
94  foreach($this->export_material as $items)
95  {
96  $images = array_merge($images, $items["images"]);
97  $files = array_merge($files, $items["files"]);
98  $js_files = array_merge($js_files, $items["js"]);
99  }
100  foreach(array_unique($images) as $image)
101  {
102  if(is_file($image))
103  {
104  copy($image, $this->export_dir."/images/".basename($image));
105  }
106  }
107  foreach(array_unique($js_files) as $js_file)
108  {
109  if(is_file($js_file))
110  {
111  copy($js_file, $this->export_dir."/js/".basename($js_file));
112  }
113  }
114  foreach(array_unique($files) as $file)
115  {
116  if(is_file($file))
117  {
118  copy($file, $this->export_dir."/files/".basename($file));
119  }
120  }
121 
122  // zip everything
123  if (true)
124  {
125  // zip it all
126  $date = time();
127  $zip_file = ilExport::_getExportDirectory($this->object->getId(), "html", "prtf").
128  "/".$date."__".IL_INST_ID."__".
129  $this->object->getType()."_".$this->object->getId().".zip";
130  ilUtil::zip($this->export_dir, $zip_file);
131  ilUtil::delDir($this->export_dir);
132  }
133 
134  return $zip_file;
135  }
136 
140  function exportHTMLPages()
141  {
142  global $tpl, $ilBench, $ilLocator;
143 
144  require_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
145  $pages = ilPortfolioPage::getAllPages($this->object->getId());
146 
147  $this->tabs = array();
148  foreach($pages as $page)
149  {
150  // substitute blog id with title
151  if($page["type"] == ilPortfolioPage::TYPE_BLOG)
152  {
153  include_once "Modules/Blog/classes/class.ilObjBlog.php";
154  $page["title"] = ilObjBlog::_lookupTitle((int)$page["title"]);
155  }
156 
157  $this->tabs[$page["id"]] = $page["title"];
158  }
159 
160  // for sub-pages, e.g. blog postings
161  $tpl_callback = array($this, "buildExportTemplate");
162 
163  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
164  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
165  include_once("./Modules/Portfolio/classes/class.ilPortfolioPage.php");
166  $has_index = false;
167  foreach ($pages as $page)
168  {
169  if (ilPortfolioPage::_exists("prtf", $page["id"]))
170  {
171  $this->active_tab = "user_page_".$page["id"];
172 
173  if($page["type"] == ilPortfolioPage::TYPE_BLOG)
174  {
175  $link_template = "prtf_".$page["id"]."_bl{TYPE}_{ID}.html";
176 
177  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
178  $blog = new ilObjBlogGUI((int)$page["title"], ilObject2GUI::WORKSPACE_OBJECT_ID);
179  $blog->exportHTMLPages($this->export_dir."/", $link_template, $tpl_callback, $this->co_page_html_export, "prtf_".$page["id"].".html");
180  }
181  else
182  {
183  $this->exportPageHTML($page["id"]);
184  $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
185  }
186 
187  if(!$has_index)
188  {
189  copy($this->export_dir."/prtf_".$page["id"].".html",
190  $this->export_dir."/index.html");
191  $has_index = true;
192  }
193  }
194  }
195  $this->co_page_html_export->exportPageElements();
196  }
197 
198  function buildExportTemplate(array $a_js_files = null)
199  {
200  global $ilTabs;
201 
202  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
203  $this->tpl->getStandardTemplate();
204  $this->tpl->addOnLoadCode('il.Tooltip.init();', 3);
205 
206  // js files
207  if(is_array($a_js_files))
208  {
209  foreach($a_js_files as $js_file)
210  {
211  $this->tpl->setCurrentBlock("js_file");
212  $this->tpl->setVariable("JS_FILE", !stristr($js_file, "://")
213  ? "./js/".basename($js_file)
214  : $js_file);
215  $this->tpl->parseCurrentBlock();
216  }
217  }
218 
219  // workaround
220  $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
221  $this->tpl->setTitle($this->object->getTitle());
222 
223  $ilTabs->clearTargets();
224  if($this->tabs)
225  {
226  foreach($this->tabs as $id => $caption)
227  {
228  $ilTabs->addTab("user_page_".$id, $caption, "prtf_".$id.".html");
229  }
230 
231  $ilTabs->activateTab($this->active_tab);
232  }
233 
234  include_once "Modules/Portfolio/classes/class.ilObjPortfolioGUI.php";
235  ilObjPortfolioGUI::renderFullscreenHeader($this->object, $this->tpl, $this->object->getOwner(), true);
236 
237  return $this->tpl;
238  }
239 
240  function writeExportFile($a_file, $a_content, $a_onload = null, $a_js_files = null)
241  {
242  $file = $this->export_dir."/".$a_file;
243  // return if file is already existing
244  if (@is_file($file))
245  {
246  return;
247  }
248 
249  // export template: page content
250  $ep_tpl = new ilTemplate("tpl.export_page.html", true, true,
251  "Modules/Portfolio");
252  $ep_tpl->setVariable("PAGE_CONTENT", $a_content);
253 
254  $this->buildExportTemplate($a_js_files);
255  $this->tpl->setContent($ep_tpl->get());
256 
257  if(is_array($a_onload))
258  {
259  foreach($a_onload as $item)
260  {
261  $this->tpl->addOnLoadCode($item);
262  }
263  }
264 
265 
266  $content = $this->tpl->get("DEFAULT", false, false, false,
267  true, true, true);
268 
269  // open file
270  if (!file_put_contents($file, $content))
271  {
272  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
273  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
274  }
275 
276  // set file permissions
277  chmod($file, 0770);
278 
279  return $file;
280  }
281 
285  function exportPageHTML($a_post_id)
286  {
287  global $lng;
288 
289  // page
290  include_once "Modules/Portfolio/classes/class.ilPortfolioPageGUI.php";
291  $pgui = new ilPortfolioPageGUI($this->object->getId(), $a_post_id);
292  $pgui->setOutputMode("offline");
293  $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
294  $page_content = $pgui->showPage();
295 
296  $material = $pgui->getExportMaterial();
297  $this->export_material[] = $material;
298 
299  $this->writeExportFile("prtf_".$a_post_id.".html", $page_content, $pgui->getJsOnloadCode(), $material["js"]);
300  }
301 }
302 
303 ?>
ILIAS Setting Class.
print $file
static _lookupTitle($a_id)
Portfolio HTML exporter class.
HTML export class for pages.
HTML export class for system styles.
_createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
Create export directory.
__construct($a_portfolio_gui, $a_object)
Constructor.
Portfolio page gui class.
global $tpl
Definition: ilias.php:8
writeExportFile($a_file, $a_content, $a_onload=null, $a_js_files=null)
static _exists($a_parent_type, $a_id, $a_lang="")
Checks whether page exists.
Class ilObjBlogGUI.
buildExportFile()
Build export file.
special template class to simplify handling of ITX/PEAR
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getAllPages($a_portfolio_id)
Get pages of portfolio.
exportPageHTML($a_post_id)
Export page html.
static renderFullscreenHeader($a_portfolio, $a_tpl, $a_user_id, $a_export=false)
Render banner, user name.
global $lng
Definition: privfeed.php:40
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
global $ilBench
Definition: ilias.php:18
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
buildExportTemplate(array $a_js_files=null)
setOutputMode($a_mode=IL_PAGE_PRESENTATION)
Set Output Mode.