ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPublicUserProfileGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
16  protected $userid; // [int]
17  protected $portfolioid; // [int]
18  protected $backurl; // [string]
19  protected $additional; // [string] used in forum
20  protected $embedded; // [bool] used in portfolio
21  protected $custom_prefs; // [array] used in portfolio
22 
28  function __construct($a_user_id = 0)
29  {
30  global $ilCtrl, $lng;
31 
32  if($a_user_id)
33  {
34  $this->setUserId($a_user_id);
35  }
36  else
37  {
38  $this->setUserId((int)$_GET["user_id"]);
39  }
40 
41  $ilCtrl->saveParameter($this, array("user_id","back_url", "user"));
42  if ($_GET["back_url"] != "")
43  {
44  $this->setBackUrl($_GET["back_url"]);
45  }
46 
47  $lng->loadLanguageModule("user");
48  }
49 
55  function setUserId($a_userid)
56  {
57  $this->userid = $a_userid;
58  }
59 
65  function getUserId()
66  {
67  return $this->userid;
68  }
69 
75  function setAdditional($a_additional)
76  {
77  $this->additional = $a_additional;
78  }
79 
85  function getAdditional()
86  {
87  return $this->additional;
88  }
89 
95  function setBackUrl($a_backurl)
96  {
97  global $ilCtrl;
98 
99  // we only allow relative links
100  $parts = parse_url($a_backurl);
101  if($parts["host"])
102  {
103  $a_backurl = "#";
104  }
105 
106  $this->backurl = $a_backurl;
107  $ilCtrl->setParameter($this, "back_url", rawurlencode($a_backurl));
108  }
109 
115  function getBackUrl()
116  {
117  return $this->backurl;
118  }
119 
125  function setCustomPrefs(array $a_prefs)
126  {
127  $this->custom_prefs = $a_prefs;
128  }
129 
139  protected function getPublicPref(ilObjUser $a_user, $a_id)
140  {
141  if(!$this->custom_prefs)
142  {
143  return $a_user->getPref($a_id);
144  }
145  else
146  {
147  return $this->custom_prefs[$a_id];
148  }
149  }
150 
151  function setEmbedded($a_value, $a_offline = false)
152  {
153  $this->embedded = (bool)$a_value;
154  $this->offline = (bool)$a_offline;
155  }
156 
160  function executeCommand()
161  {
162  global $ilCtrl, $tpl;
163 
164  if(!self::validateUser($this->getUserId()))
165  {
166  return;
167  }
168 
169  $next_class = $ilCtrl->getNextClass($this);
170  $cmd = $ilCtrl->getCmd();
171 
172  $tpl->getStandardTemplate();
173 
174  switch($next_class)
175  {
176  case "ilobjportfoliogui":
177  $portfolio_id = $this->getProfilePortfolio();
178  if($portfolio_id)
179  {
180  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
181  $plink = new ilPermanentLinkGUI("usr", $this->getUserId());
182  $plink = $plink->getHTML();
183 
184  include_once "Modules/Portfolio/classes/class.ilObjPortfolioGUI.php";
185  $gui = new ilObjPortfolioGUI($portfolio_id); // #11876
186  $gui->setAdditional($this->getAdditional());
187  $gui->setPermaLink($plink);
188  $ilCtrl->forwardCommand($gui);
189  break;
190  }
191 
192  default:
193  $ret = $this->$cmd();
194  $tpl->setContent($ret);
195 
196  // only for direct links
197  if ($_GET["baseClass"] == "ilPublicUserProfileGUI")
198  {
199  $tpl->show();
200  }
201  break;
202  }
203  }
204 
208  function view()
209  {
210  return $this->getHTML();
211  }
212 
216  function getHTML()
217  {
218  global $ilCtrl, $ilSetting;
219 
220  if($this->embedded)
221  {
222  return $this->getEmbeddable();
223  }
224 
225  // #15438 - (currently) inactive user?
226  $is_active = true;
227  $user = new ilObjUser($this->getUserId());
228  if(!$user->getActive() ||
229  !$user->checkTimeLimit())
230  {
231  $is_active = false;
232  }
233 
234  if($is_active && $this->getProfilePortfolio())
235  {
236  $ilCtrl->redirectByClass("ilobjportfoliogui", "preview");
237  }
238  else
239  {
240  $this->renderTitle();
241 
242  if(!$is_active)
243  {
244  return;
245  }
246 
247  // Check from Database if value
248  // of public_profile = "y" show user infomation
249  $user = new ilObjUser($this->getUserId());
250  if ($user->getPref("public_profile") != "y" &&
251  ($user->getPref("public_profile") != "g" || !$ilSetting->get('enable_global_profiles')) &&
252  !$this->custom_prefs)
253  {
254  return;
255  }
256 
257  return $this->getEmbeddable(true);
258  }
259  }
260 
266  function getEmbeddable($a_add_goto = false)
267  {
269 
270  // get user object
271  if (!ilObject::_exists($this->getUserId()))
272  {
273  return "";
274  }
275  $user = new ilObjUser($this->getUserId());
276 
277  $tpl = new ilTemplate("tpl.usr_public_profile.html", true, true,
278  "Services/User");
279 
280  $tpl->setVariable("ROWCOL1", "tblrow1");
281  $tpl->setVariable("ROWCOL2", "tblrow2");
282 
283  if(!$this->offline && $ilUser->getId() != ANONYMOUS_USER_ID)
284  {
285  $ref_url = str_replace("&amp;", "&", $this->getBackUrl());
286  if(!$ref_url)
287  {
288  $ref_url = basename($_SERVER['REQUEST_URI']);
289  }
290 
291  $tpl->setCurrentBlock("mail");
292  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
293  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
294  $tpl->setVariable('HREF_MAIL', ilMailFormCall::getLinkTarget($ref_url, '', array(), array('type' => 'new', 'rcp_to' => urlencode($user->getLogin()))));
295  $tpl->parseCurrentBlock();
296  }
297 
298  $first_name = "";
299  if($this->getPublicPref($user, "public_title") == "y")
300  {
301  $first_name .= $user->getUTitle()." ";
302  }
303  $first_name .= $user->getFirstName();
304 
305  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
306  $tpl->setVariable("FIRSTNAME", $first_name);
307  $tpl->setVariable("LASTNAME", $user->getLastName());
308 
309  if(!$this->offline)
310  {
311  // vcard
312  $tpl->setCurrentBlock("vcard");
313  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
314  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
315  $ilCtrl->setParameter($this, "user", $this->getUserId());
316  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
317  //$tpl->setVariable("IMG_VCARD", ilUtil::getImagePath("vcard.png"));
318  }
319 
320  $webspace_dir = ilUtil::getWebspaceDir("user");
321  $check_dir = ilUtil::getWebspaceDir();
322  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999);
323  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
324 
325  if (!@is_file($check_file))
326  {
327  $imagefile = $check_file =
328  ilObjUser::_getPersonalPicturePath($user->getId(), "small", false, true);
329  }
330 
331  if ($this->getPublicPref($user, "public_upload")=="y" && $imagefile != "")
332  {
333  //Getting the flexible path of image form ini file
334  //$webspace_dir = ilUtil::getWebspaceDir("output");
335  $tpl->setCurrentBlock("image");
336  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
337  $tpl->setVariable("IMAGE_PATH", $imagefile);
338  $tpl->setVariable("IMAGE_ALT", $lng->txt("personal_picture"));
339  $tpl->parseCurrentBlock();
340  }
341 
342  // address
343  if ($this->getPublicPref($user, "public_street") == "y" ||
344  $this->getPublicPref($user, "public_zipcode") == "y" ||
345  $this->getPublicPref($user, "public_city") == "y" ||
346  $this->getPublicPref($user, "public_country") == "y")
347  {
348  $address = array();
349  $val_arr = array ("getStreet" => "street",
350  "getZipcode" => "zipcode",
351  "getCity" => "city",
352  "getCountry" => "country",
353  "getSelectedCountry" => "sel_country");
354  foreach ($val_arr as $key => $value)
355  {
356  // if value "y" show information
357  if ($this->getPublicPref($user, "public_".$value) == "y")
358  {
359  $address_value = $user->$key();
360 
361  // only if set
362  if (trim($address_value) != "")
363  {
364  switch($value)
365  {
366  case "street":
367  $address[0] = $address_value;
368  break;
369 
370  case "zipcode":
371  case "city":
372  $address[1] .= " ".$address_value;
373  break;
374 
375  case "sel_country":
376  $lng->loadLanguageModule("meta");
377  $address[2] = $lng->txt("meta_c_".$address_value);
378  break;
379 
380  case "country":
381  $address[2] = $address_value;
382  break;
383  }
384  }
385  }
386  }
387  if(sizeof($address))
388  {
389  $tpl->setCurrentBlock("address_line");
390  foreach($address as $line)
391  {
392  if(trim($line))
393  {
394  $tpl->setVariable("TXT_ADDRESS_LINE", trim($line));
395  $tpl->parseCurrentBlock();
396  }
397  }
398  $tpl->setCurrentBlock("address");
399  $tpl->setVariable("TXT_ADDRESS", $lng->txt("address"));
400  $tpl->parseCurrentBlock();
401  }
402  }
403 
404  // institution / department
405  if ($this->getPublicPref($user, "public_institution") == "y" ||
406  $this->getPublicPref($user, "public_department") == "y")
407  {
408  $tpl->setCurrentBlock("inst_dep");
409  $sep = "";
410  if ($this->getPublicPref($user, "public_institution") == "y")
411  {
412  $h = $lng->txt("institution");
413  $v = $user->getInstitution();
414  $sep = " / ";
415  }
416  if ($this->getPublicPref($user, "public_department") == "y")
417  {
418  $h.= $sep.$lng->txt("department");
419  $v.= $sep.$user->getDepartment();
420  }
421  $tpl->setVariable("TXT_INST_DEP", $h);
422  $tpl->setVariable("INST_DEP", $v);
423  $tpl->parseCurrentBlock();
424  }
425 
426  // contact
427  $val_arr = array(
428  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
429  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email");
430  $v = $sep = "";
431  foreach ($val_arr as $key => $value)
432  {
433  // if value "y" show information
434  if ($this->getPublicPref($user, "public_".$value) == "y")
435  {
436  $v.= $sep.$lng->txt($value).": ".$user->$key();
437  $sep = "<br />";
438  }
439  }
440  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
441  {
442  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
443 
444  foreach ($im_arr as $im_name)
445  {
446  if ($im_id = $user->getInstantMessengerId($im_name))
447  {
448  if ($this->getPublicPref($user, "public_im_".$im_name) != "n")
449  {
450  $v.= $sep.$lng->txt('im_'.$im_name).": ".$im_id;
451  $sep = "<br />";
452  }
453  }
454  }
455  }
456  if ($v != "")
457  {
458  $tpl->parseCurrentBlock("contact");
459  $tpl->setVariable("TXT_CONTACT", $lng->txt("contact"));
460  $tpl->setVariable("CONTACT", $v);
461  $tpl->parseCurrentBlock();
462  }
463 
464 
465  $val_arr = array(
466  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
467 
468  foreach ($val_arr as $key => $value)
469  {
470  // if value "y" show information
471  if ($this->getPublicPref($user, "public_".$value) == "y")
472  {
473  $tpl->setCurrentBlock("profile_data");
474  $tpl->setVariable("TXT_DATA", $lng->txt($value));
475  $tpl->setVariable("DATA", $user->$key());
476  $tpl->parseCurrentBlock();
477  }
478  }
479 
480  // delicious row
481  //$d_set = new ilSetting("delicious");
482  if ($this->getPublicPref($user, "public_delicious") == "y")
483  {
484  $tpl->setCurrentBlock("delicious_row");
485  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
486  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
487  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.png"));
488  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
489  $tpl->parseCurrentBlock();
490  }
491 
492  // map
493  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
495  $this->getPublicPref($user, "public_location") == "y" &&
496  $user->getLatitude() != "")
497  {
498  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
499 
500  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
501  $map_gui = new ilGoogleMapGUI();
502 
503  $map_gui->setMapId("user_map");
504  $map_gui->setWidth("350px");
505  $map_gui->setHeight("230px");
506  $map_gui->setLatitude($user->getLatitude());
507  $map_gui->setLongitude($user->getLongitude());
508  $map_gui->setZoom($user->getLocationZoom());
509  $map_gui->setEnableNavigationControl(true);
510  $map_gui->addUserMarker($user->getId());
511 
512  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
513  }
514 
515  // additional defined user data fields
516  include_once './Services/User/classes/class.ilUserDefinedFields.php';
517  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
518  $user_defined_data = $user->getUserDefinedData();
519  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
520  {
521  // public setting
522  if ($this->getPublicPref($user, "public_udf_".$definition["field_id"]) == "y")
523  {
524  if ($user_defined_data["f_".$definition["field_id"]] != "")
525  {
526  $tpl->setCurrentBlock("udf_data");
527  $tpl->setVariable("TXT_UDF_DATA", $definition["field_name"]);
528  $tpl->setVariable("UDF_DATA", $user_defined_data["f_".$definition["field_id"]]);
529  $tpl->parseCurrentBlock();
530  }
531  }
532  }
533 
534  // additional information
535  $additional = $this->getAdditional();
536  if (is_array($additional))
537  {
538  foreach($additional as $key => $val)
539  {
540  $tpl->setCurrentBlock("profile_data");
541  $tpl->setVariable("TXT_DATA", $key);
542  $tpl->setVariable("DATA", $val);
543  $tpl->parseCurrentBlock();
544  }
545  }
546 
547  $goto = "";
548  if($a_add_goto)
549  {
550  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
551  $goto = new ilPermanentLinkGUI("usr", $user->getId());
552  $goto = $goto->getHTML();
553  }
554 
555  return $tpl->get().$goto;
556  }
557 
561  function deliverVCard()
562  {
563  // get user object
564  if (!ilObject::_exists($this->getUserId()))
565  {
566  return "";
567  }
568  $user = new ilObjUser($this->getUserId());
569 
570  require_once "./Services/User/classes/class.ilvCard.php";
571  $vcard = new ilvCard();
572 
573  // ilsharedresourceGUI: embedded in shared portfolio
574  if ($user->getPref("public_profile") != "y" &&
575  $user->getPref("public_profile") != "g" &&
576  $_GET["baseClass"] != "ilsharedresourceGUI")
577  {
578  return;
579  }
580 
581  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
582  $vcard->setNickname($user->getLogin());
583 
584  $webspace_dir = ilUtil::getWebspaceDir("output");
585  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
586  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
587  {
588  $fh = fopen($imagefile, "r");
589  if ($fh)
590  {
591  $image = fread($fh, filesize($imagefile));
592  fclose($fh);
593  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
594  $mimetype = ilObjMediaObject::getMimeType($imagefile);
595  if (preg_match("/^image/", $mimetype))
596  {
597  $type = $mimetype;
598  }
599  $vcard->setPhoto($image, $type);
600  }
601  }
602 
603  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
604  "getStreet" => "street",
605  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country",
606  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
607  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
608  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
609 
610  $org = array();
611  $adr = array();
612  foreach ($val_arr as $key => $value)
613  {
614  // if value "y" show information
615  if ($user->getPref("public_".$value) == "y")
616  {
617  switch ($value)
618  {
619  case "institution":
620  $org[0] = $user->$key();
621  break;
622  case "department":
623  $org[1] = $user->$key();
624  break;
625  case "street":
626  $adr[2] = $user->$key();
627  break;
628  case "zipcode":
629  $adr[5] = $user->$key();
630  break;
631  case "city":
632  $adr[3] = $user->$key();
633  break;
634  case "country":
635  $adr[6] = $user->$key();
636  break;
637  case "phone_office":
638  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
639  break;
640  case "phone_home":
641  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
642  break;
643  case "phone_mobile":
644  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
645  break;
646  case "fax":
647  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
648  break;
649  case "email":
650  $vcard->setEmail($user->$key());
651  break;
652  case "hobby":
653  $vcard->setNote($user->$key());
654  break;
655  }
656  }
657  }
658 
659  if (count($org))
660  {
661  $vcard->setOrganization(join(";", $org));
662  }
663  if (count($adr))
664  {
665  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
666  }
667 
668  ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
669  }
670 
676  protected static function validateUser($a_user_id)
677  {
678  global $ilUser;
679 
680  if (ilObject::_lookupType($a_user_id) != "usr")
681  {
682  return false;
683  }
684  $user = new ilObjUser($a_user_id);
685  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
686  {
687  // #12151
688  if($user->getPref("public_profile") == "y")
689  {
690  ilUtil::redirect("login.php?cmd=force_login&target=usr_".$a_user_id);
691  }
692  return false;
693  }
694  return true;
695  }
696 
697  function renderTitle()
698  {
699  global $tpl, $ilTabs, $lng;
700 
701  $tpl->resetHeaderBlock();
702 
703  include_once("./Services/User/classes/class.ilUserUtil.php");
704  $tpl->setTitle(ilUserUtil::getNamePresentation($this->getUserId()));
705  $tpl->setTitleIcon(ilObjUser::_getPersonalPicturePath($this->getUserId(), "xxsmall"));
706 
707  $back = ($this->getBackUrl() != "")
708  ? $this->getBackUrl()
709  : $_GET["back_url"];
710 
711  if ($back != "")
712  {
713  $ilTabs->clearTargets();
714  $ilTabs->setBackTarget($lng->txt("back"),
715  $back);
716  }
717  }
718 
724  protected function getProfilePortfolio()
725  {
726  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
727  $portfolio_id = ilObjPortfolio::getDefaultPortfolio($this->getUserId());
728  if($portfolio_id)
729  {
730  include_once('./Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php');
731  $access_handler = new ilPortfolioAccessHandler();
732  if($access_handler->checkAccess("read", "", $portfolio_id))
733  {
734  return $portfolio_id;
735  }
736  }
737  }
738 }
739 
740 ?>