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