ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPermanentLinkGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
37 {
38  protected $align_center = true;
39 
43  function __construct($a_type, $a_id, $a_append = "", $a_target = "")
44  {
45  $this->setType($a_type);
46  $this->setId($a_id);
47  $this->setAppend($a_append);
48  $this->setIncludePermanentLinkText(true);
49  $this->setTarget($a_target);
50  }
51 
57  function setIncludePermanentLinkText($a_includepermanentlinktext)
58  {
59  $this->includepermanentlinktext = $a_includepermanentlinktext;
60  }
61 
68  {
69  return $this->includepermanentlinktext;
70  }
71 
77  function setType($a_type)
78  {
79  $this->type = $a_type;
80  }
81 
87  function getType()
88  {
89  return $this->type;
90  }
91 
97  function setId($a_id)
98  {
99  $this->id = $a_id;
100  }
101 
107  function getId()
108  {
109  return $this->id;
110  }
111 
117  function setAppend($a_append)
118  {
119  $this->append = $a_append;
120  }
121 
127  function getAppend()
128  {
129  return $this->append;
130  }
131 
137  function setTarget($a_target)
138  {
139  $this->target = $a_target;
140  }
141 
147  function getTarget()
148  {
149  return $this->target;
150  }
151 
157  function setTitle($a_val)
158  {
159  $this->title = $a_val;
160  }
161 
167  function getTitle()
168  {
169  return $this->title;
170  }
171 
177  function setAlignCenter($a_val)
178  {
179  $this->align_center = $a_val;
180  }
181 
187  function getAlignCenter()
188  {
189  return $this->align_center;
190  }
191 
195  function getHTML()
196  {
197  global $lng, $ilCtrl, $ilObjDataCache, $ilDB;
198 
199  $tpl = new ilTemplate("tpl.permanent_link.html", true, true,
200  "Services/PermanentLink");
201 
202  include_once('classes/class.ilLink.php');
203  $href = ilLink::_getStaticLink($this->getId(), $this->getType(),
204  true, $this->getAppend());
205  if ($this->getIncludePermanentLinkText())
206  {
207  $tpl->setVariable("TXT_PERMA", $lng->txt("perma_link").":");
208  }
209 
210  $title = '';
211 
212  // fetch default title for bookmark
213 
214  if ($this->getTitle() != "")
215  {
216  $title = $this->getTitle();
217  }
218  else
219  {
220  $obj_id = $ilObjDataCache->lookupObjId($this->getId());
221  $title = $ilObjDataCache->lookupTitle($obj_id);
222  }
223  #if (!$title)
224  # $bookmark->setTitle("untitled");
225 
226  $tpl->setVariable("TXT_BOOKMARK_DEFAULT", $title);
227 
228  $tpl->setVariable("LINK", $href);
229 
230  if ($this->getAlignCenter())
231  {
232  $tpl->setVariable("ALIGN", "center");
233  }
234  else
235  {
236  $tpl->setVariable("ALIGN", "left");
237  }
238 
239  if ($this->getTarget() != "")
240  {
241  $tpl->setVariable("TARGET", 'target="'.$this->getTarget().'"');
242  }
243 
244 
245  // bookmark links
246  $bm_html = self::_getBookmarksSelectionList($title, $href);
247 
248  if ($bm_html)
249  {
250  $tpl->setVariable('SELECTION_LIST', $bm_html);
251  }
252 
253  return $tpl->get();
254  }
255 
256 
261  public static function _getBookmarksSelectionList($title, $href)
262  {
263  global $ilDB, $lng, $ilSetting;
264 
265  // social bookmarkings
266 
267  $q = 'SELECT sbm_title, sbm_link, sbm_icon, sbm_active FROM bookmark_social_bm WHERE sbm_active = 1 ORDER BY sbm_title';
268  $rset = $ilDB->query($q);
269 
270  include_once("./Services/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
271 
272  $current_selection_list = new ilAdvancedSelectionListGUI();
273  $current_selection_list->setListTitle($lng->txt("bm_add_to_social_bookmarks"));
274  $current_selection_list->setId("socialbm_actions");
275  $current_selection_list->setUseImages(true);
276 
277  $cnt = 0;
278 
279  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID && !$ilSetting->get('disable_bookmarks'))
280  {
281  $linktpl = 'ilias.php?cmd=redirect&baseClass=ilPersonalDesktopGUI&redirectClass=ilbookmarkadministrationgui&redirectCmd=newFormBookmark&param_bmf_id=1&param_return_to=true&param_bm_title='. urlencode($title) . '&param_bm_link=' . urlencode(urlencode($href))."&param_return_to_url=".urlencode(urlencode($_SERVER['REQUEST_URI']));
282  $current_selection_list->addItem($lng->txt("bm_add_to_ilias"), '', $linktpl, ilUtil::getImagePath('socialbookmarks/icon_bm_15x15.gif') , $lng->txt("bm_add_to_ilias"), '_top');
283  $cnt++;
284  }
285 
286  while ($row = $ilDB->fetchObject($rset))
287  {
288  $linktpl = $row->sbm_link;
289  $linktpl = str_replace('{LINK}', urlencode($href), $linktpl);
290  $linktpl = str_replace('{TITLE}', urlencode($title), $linktpl);
291  $current_selection_list->addItem($row->sbm_title, '', $linktpl, $row->sbm_icon, $row->title, '_blank');
292  $cnt++;
293  }
294 
295  if ($cnt == 1 && $_SESSION["AccountId"] != ANONYMOUS_USER_ID && !$ilSetting->get('disable_bookmarks'))
296  {
297  $loc_tpl = new ilTemplate('tpl.single_link.html', true, true, 'Services/PermanentLink');
298  $loc_tpl->setVariable("TXT_ADD_TO_ILIAS_BM", $lng->txt("bm_add_to_ilias"));
299  $loc_tpl->setVariable("URL_ADD_TO_BM", 'ilias.php?cmd=redirect&baseClass=ilPersonalDesktopGUI&redirectClass=ilbookmarkadministrationgui&redirectCmd=newFormBookmark&param_bmf_id=1&param_return_to=true&param_bm_title='. urlencode($title) . '&param_bm_link=' . urlencode(urlencode($href))."&param_return_to_url=".urlencode(urlencode($_SERVER['REQUEST_URI'])));
300  $loc_tpl->setVariable("ICON", ilUtil::getImagePath('icon_bm.gif'));
301  return $loc_tpl->get();
302  }
303  else if ($cnt >= 1)
304  {
305  return $current_selection_list->getHTML();
306  }
307  else
308  return '';
309 
310  }
311 }
312 
313 ?>