ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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_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->object->getStyleSheetId()); */
61  $this->co_page_html_export->createDirectories();
62  $this->co_page_html_export->exportStyles();
63  $this->co_page_html_export->exportSupportScripts();
64 
65  // banner / profile picture
66  $prfa_set = new ilSetting("prfa");
67  if($prfa_set->get("banner"))
68  {
69  $banner = $this->object->getImageFullPath();
70  copy($banner, $this->export_dir."/".basename($banner));
71  }
72  $ppic = ilObjUser::_getPersonalPicturePath($this->object->getOwner(), "big");
73  if($ppic)
74  {
75  $ppic = array_shift(explode("?", $ppic));
76  copy($ppic, $this->export_dir."/".basename($ppic));
77  }
78 
79  // export pages
80  $this->exportHTMLPages();
81 
82  // zip everything
83  if (true)
84  {
85  // zip it all
86  $date = time();
87  $zip_file = ilExport::_getExportDirectory($this->object->getId(), "html", "prtf").
88  "/".$date."__".IL_INST_ID."__".
89  $this->object->getType()."_".$this->object->getId().".zip";
90  ilUtil::zip($this->export_dir, $zip_file);
91  ilUtil::delDir($this->export_dir);
92  }
93 
94  return $zip_file;
95  }
96 
100  function exportHTMLPages()
101  {
102  global $tpl, $ilBench, $ilLocator;
103 
104  require_once "Services/Portfolio/classes/class.ilPortfolioPage.php";
105  $pages = ilPortfolioPage::getAllPages($this->object->getId());
106 
107  $this->tabs = array();
108  foreach($pages as $page)
109  {
110  // substitute blog id with title
111  if($page["type"] == ilPortfolioPage::TYPE_BLOG)
112  {
113  include_once "Modules/Blog/classes/class.ilObjBlog.php";
114  $page["title"] = ilObjBlog::_lookupTitle((int)$page["title"]);
115  }
116 
117  $this->tabs[$page["id"]] = $page["title"];
118  }
119 
120  // for sub-pages, e.g. blog postings
121  $tpl_callback = array($this, "buildExportTemplate");
122 
123  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
124  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
125  $has_index = false;
126  foreach ($pages as $page)
127  {
128  if (ilPageObject::_exists("prtf", $page["id"]))
129  {
130  $this->active_tab = "user_page_".$page["id"];
131 
132  if($page["type"] == ilPortfolioPage::TYPE_BLOG)
133  {
134  $link_template = "prtf_".$page["id"]."_bl{TYPE}_{ID}.html";
135 
136  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
137  $blog = new ilObjBlogGUI((int)$page["title"], ilObject2GUI::WORKSPACE_OBJECT_ID);
138  $blog->exportHTMLPages($this->export_dir."/", $link_template, $tpl_callback, $this->co_page_html_export, "prtf_".$page["id"].".html");
139  }
140  else
141  {
142  $this->exportPageHTML($page["id"]);
143  $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
144  }
145 
146  if(!$has_index)
147  {
148  copy($this->export_dir."/prtf_".$page["id"].".html",
149  $this->export_dir."/index.html");
150  $has_index = true;
151  }
152  }
153  }
154  $this->co_page_html_export->exportPageElements();
155  }
156 
158  {
159  global $ilTabs;
160 
161  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
162  $this->tpl->getStandardTemplate();
163  $this->tpl->addOnLoadCode('il.Tooltip.init();', 3);
164 
165  // workaround
166  $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
167  $this->tpl->setTitle($this->object->getTitle());
168 
169  $ilTabs->clearTargets();
170  if($this->tabs)
171  {
172  foreach($this->tabs as $id => $caption)
173  {
174  $ilTabs->addTab("user_page_".$id, $caption, "prtf_".$id.".html");
175  }
176 
177  $ilTabs->activateTab($this->active_tab);
178  }
179 
180  include_once "Services/Portfolio/classes/class.ilObjPortfolioGUI.php";
181  ilObjPortfolioGUI::renderFullscreenHeader($this->object, $this->tpl, $this->object->getOwner(), true);
182  $this->tpl->setFrameFixedWidth(true);
183 
184  return $this->tpl;
185  }
186 
187  function writeExportFile($a_file, $a_content, $a_onload = null)
188  {
189  $file = $this->export_dir."/".$a_file;
190  // return if file is already existing
191  if (@is_file($file))
192  {
193  return;
194  }
195 
196  // export template: page content
197  $ep_tpl = new ilTemplate("tpl.export_page.html", true, true,
198  "Services/Portfolio");
199  $ep_tpl->setVariable("PAGE_CONTENT", $a_content);
200 
201  $this->buildExportTemplate();
202  $this->tpl->setContent($ep_tpl->get());
203 
204  if(is_array($a_onload))
205  {
206  foreach($a_onload as $item)
207  {
208  $this->tpl->addOnLoadCode($item);
209  }
210  }
211 
212 
213  $content = $this->tpl->get("DEFAULT", false, false, false,
214  true, true, true);
215 
216  // open file
217  if (!file_put_contents($file, $content))
218  {
219  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
220  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
221  }
222 
223  // set file permissions
224  chmod($file, 0770);
225 
226  return $file;
227  }
228 
232  function exportPageHTML($a_post_id)
233  {
234  global $lng;
235 
236  // page
237  include_once "Services/Portfolio/classes/class.ilPortfolioPageGUI.php";
238  $pgui = new ilPortfolioPageGUI($this->object->getId(), $a_post_id);
239  $pgui->setOutputMode("offline");
240  $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
241  $page_content = $pgui->showPage();
242 
243  $this->writeExportFile("prtf_".$a_post_id.".html", $page_content, $pgui->getJsOnloadCode());
244  }
245 }
246 
247 ?>