ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjBlog.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "Services/Object/classes/class.ilObject2.php";
6 
15 class ilObjBlog extends ilObject2
16 {
17  protected $notes; // [bool]
18  protected $bg_color; // [string]
19  protected $font_color; // [string]
20  protected $img; // [string]
21  protected $ppic; // [string]
22  protected $rss; // [bool]
23  protected $approval; // [bool]
24  protected $style; // [bool]
25 
26  function initType()
27  {
28  $this->type = "blog";
29  }
30 
31  protected function doRead()
32  {
33  global $ilDB;
34 
35  $set = $ilDB->query("SELECT * FROM il_blog".
36  " WHERE id = ".$ilDB->quote($this->id, "integer"));
37  $row = $ilDB->fetchAssoc($set);
38  $this->setNotesStatus((bool)$row["notes"]);
39  $this->setProfilePicture((bool)$row["ppic"]);
40  $this->setBackgroundColor($row["bg_color"]);
41  $this->setFontColor($row["font_color"]);
42  $this->setImage($row["img"]);
43  $this->setRSS($row["rss_active"]);
44  $this->setApproval($row["approval"]);
45 
46  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
48  }
49 
50  protected function doCreate()
51  {
52  global $ilDB;
53 
54  $ilDB->manipulate("INSERT INTO il_blog (id,notes,ppic,rss_active,approval) VALUES (".
55  $ilDB->quote($this->id, "integer").",".
56  $ilDB->quote(true, "integer").",".
57  $ilDB->quote(true, "integer").",".
58  $ilDB->quote(true, "integer").",".
59  $ilDB->quote(false, "integer").")");
60 
61  /*
62  if ($this->getStyleSheetId() > 0)
63  {
64  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
65  ilObjStyleSheet::writeStyleUsage($this->id, $this->getStyleSheetId());
66  }
67  */
68  }
69 
70  protected function doDelete()
71  {
72  global $ilDB;
73 
74  $this->deleteImage();
75 
76  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
78 
79  // remove all notifications
80  include_once "./Services/Notification/classes/class.ilNotification.php";
82 
83  $ilDB->manipulate("DELETE FROM il_blog".
84  " WHERE id = ".$ilDB->quote($this->id, "integer"));
85  }
86 
87  protected function doUpdate()
88  {
89  global $ilDB;
90 
91  if($this->id)
92  {
93  $ilDB->manipulate("UPDATE il_blog".
94  " SET notes = ".$ilDB->quote($this->getNotesStatus(), "integer").
95  ",ppic = ".$ilDB->quote($this->hasProfilePicture(), "integer").
96  ",bg_color = ".$ilDB->quote($this->getBackgroundColor(), "text").
97  ",font_color = ".$ilDB->quote($this->getFontcolor(), "text").
98  ",img = ".$ilDB->quote($this->getImage(), "text").
99  ",rss_active = ".$ilDB->quote($this->hasRSS(), "integer").
100  ",approval = ".$ilDB->quote($this->hasApproval(), "integer").
101  " WHERE id = ".$ilDB->quote($this->id, "integer"));
102 
103 
104  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
106  }
107  }
108 
109  protected function doCloneObject(ilObjBlog $new_obj, $a_target_id, $a_copy_id = null)
110  {
111  // banner?
112  $img = $this->getImage();
113  if($img)
114  {
115  $new_obj->setImage($img);
116 
117  $source = $this->initStorage($this->getId());
118  $target = $new_obj->initStorage($new_obj->getId());
119 
120  copy($source.$img, $target.$img);
121  }
122 
123  $new_obj->setNotesStatus($this->getNotesStatus());
124  $new_obj->setProfilePicture($this->hasProfilePicture());
125  $new_obj->setBackgroundColor($this->getBackgroundColor());
126  $new_obj->setFontColor($this->getFontColor());
127  $new_obj->setRSS($this->hasRSS());
128  $new_obj->setApproval($this->hasApproval());
129  $new_obj->update();
130 
131  // set/copy stylesheet
132  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
133  $style_id = $this->getStyleSheetId();
134  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
135  {
136  $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
137  $new_id = $style_obj->ilClone();
138  $new_obj->setStyleSheetId($new_id);
139  $new_obj->update();
140  }
141  }
142 
148  function getNotesStatus()
149  {
150  return $this->notes;
151  }
152 
158  function setNotesStatus($a_status)
159  {
160  $this->notes = (bool)$a_status;
161  }
162 
168  function hasProfilePicture()
169  {
170  return $this->ppic;
171  }
172 
178  function setProfilePicture($a_status)
179  {
180  $this->ppic = (bool)$a_status;
181  }
182 
189  {
190  if(!$this->bg_color)
191  {
192  $this->bg_color = "ffffff";
193  }
194  return $this->bg_color;
195  }
196 
202  function setBackgroundColor($a_value)
203  {
204  $this->bg_color = (string)$a_value;
205  }
206 
212  function getFontColor()
213  {
214  if(!$this->font_color)
215  {
216  $this->font_color = "505050";
217  }
218  return $this->font_color;
219  }
220 
226  function setFontColor($a_value)
227  {
228  $this->font_color = (string)$a_value;
229  }
230 
236  function getImage()
237  {
238  return $this->img;
239  }
240 
246  function setImage($a_value)
247  {
248  $this->img = (string)$a_value;
249  }
250 
256  function getImageFullPath($a_as_thumb = false)
257  {
258  if($this->img)
259  {
260  $path = $this->initStorage($this->id);
261  if(!$a_as_thumb)
262  {
263  return $path.$this->img;
264  }
265  else
266  {
267  return $path."thb_".$this->img;
268  }
269  }
270  }
271 
275  public function deleteImage()
276  {
277  if($this->id)
278  {
279  include_once "Modules/Blog/classes/class.ilFSStorageBlog.php";
280  $storage = new ilFSStorageBlog($this->id);
281  $storage->delete();
282 
283  $this->setImage(null);
284 
285  $this->handleQuotaUpdate();
286  }
287  }
288 
296  public static function initStorage($a_id, $a_subdir = null)
297  {
298  include_once "Modules/Blog/classes/class.ilFSStorageBlog.php";
299  $storage = new ilFSStorageBlog($a_id);
300  $storage->create();
301 
302  $path = $storage->getAbsolutePath()."/";
303 
304  if($a_subdir)
305  {
306  $path .= $a_subdir."/";
307 
308  if(!is_dir($path))
309  {
310  mkdir($path);
311  }
312  }
313 
314  return $path;
315  }
316 
323  function uploadImage(array $a_upload)
324  {
325  if(!$this->id)
326  {
327  return false;
328  }
329 
330  $this->deleteImage();
331 
332  // #10074
333  $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $a_upload["name"]);
334 
335  $path = $this->initStorage($this->id);
336  $original = "org_".$this->id."_".$clean_name;
337  $thumb = "thb_".$this->id."_".$clean_name;
338  $processed = $this->id."_".$clean_name;
339 
340  if(@move_uploaded_file($a_upload["tmp_name"], $path.$original))
341  {
342  chmod($path.$original, 0770);
343 
344  $blga_set = new ilSetting("blga");
345  $dimensions = $blga_set->get("banner_width")."x".
346  $blga_set->get("banner_height");
347 
348  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
349  // taking only frame [0] to avoid problems with animated gifs
350  $original_file = ilUtil::escapeShellArg($path.$original);
351  $thumb_file = ilUtil::escapeShellArg($path.$thumb);
352  $processed_file = ilUtil::escapeShellArg($path.$processed);
353  ilUtil::execConvert($original_file."[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
354  ilUtil::execConvert($original_file."[0] -geometry ".$dimensions."! -quality 100 JPEG:".$processed_file);
355 
356  $this->setImage($processed);
357 
358  $this->handleQuotaUpdate();
359 
360  return true;
361  }
362  return false;
363  }
364 
370  function hasRSS()
371  {
372  return $this->rss;
373  }
374 
380  function setRSS($a_status)
381  {
382  $this->rss = (bool)$a_status;
383  }
384 
390  function hasApproval()
391  {
392  return (bool)$this->approval;
393  }
394 
400  function setApproval($a_status)
401  {
402  $this->approval = (bool)$a_status;
403  }
404 
410  function getStyleSheetId()
411  {
412  return (int)$this->style;
413  }
414 
420  function setStyleSheetId($a_style)
421  {
422  $this->style = (int)$a_style;
423  }
424 
425  static function sendNotification($a_action, $a_in_wsp, $a_blog_node_id, $a_posting_id, $a_comment = null)
426  {
427  global $ilUser;
428 
429  // get blog object id (repository or workspace)
430  if($a_in_wsp)
431  {
432  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
433  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
434  $tree = new ilWorkspaceTree($ilUser->getId()); // owner of tree is irrelevant
435  $blog_obj_id = $tree->lookupObjectId($a_blog_node_id);
436  $access_handler = new ilWorkspaceAccessHandler($tree);
437  }
438  else
439  {
440  $blog_obj_id = ilObject::_lookupObjId($a_blog_node_id);
441  $access_handler = null;
442  }
443  if(!$blog_obj_id)
444  {
445  return;
446  }
447 
448  include_once "./Modules/Blog/classes/class.ilBlogPosting.php";
449  $posting = new ilBlogPosting($a_posting_id);
450 
451  // #11138
452  $ignore_threshold = ($a_action == "comment");
453 
454  // approval handling
455  $admin_only = false;
456  if(!$posting->isApproved())
457  {
458  $blog = new self($blog_obj_id, false);
459  if($blog->hasApproval())
460  {
461  switch($a_action)
462  {
463  case "update":
464  // un-approved posting was updated - no notifications
465  return;
466 
467  case "new":
468  // un-approved posting was activated - admin-only notification
469  $admin_only = true;
470  $ignore_threshold = true;
471  break;
472  }
473  }
474  }
475 
476  // recipients
477  include_once "./Services/Notification/classes/class.ilNotification.php";
479  $blog_obj_id, $a_posting_id, $ignore_threshold);
480  if(!sizeof($users))
481  {
482  return;
483  }
484 
485  include_once "./Services/Notification/classes/class.ilSystemNotification.php";
486  $ntf = new ilSystemNotification($a_in_wsp);
487  $ntf->setLangModules(array("blog"));
488  $ntf->setRefId($a_blog_node_id);
489  $ntf->setChangedByUserId($ilUser->getId());
490  $ntf->setSubjectLangId('blog_change_notification_subject');
491  $ntf->setIntroductionLangId('blog_change_notification_body_'.$a_action);
492  $ntf->addAdditionalInfo('blog_posting', $posting->getTitle());
493  if($a_comment)
494  {
495  $ntf->addAdditionalInfo('comment', $a_comment, true);
496  }
497  $ntf->setGotoLangId('blog_change_notification_link');
498  $ntf->setReasonLangId('blog_change_notification_reason');
499 
500  $notified = $ntf->sendMail($users, "_".$a_posting_id,
501  ($admin_only ? "write" : "read"));
502 
503  // #14387
504  if(sizeof($notified))
505  {
506  ilNotification::updateNotificationTime(ilNotification::TYPE_BLOG, $blog_obj_id, $notified, $a_posting_id);
507  }
508  }
509 
515  static function deliverRSS($a_wsp_id)
516  {
517  global $tpl, $ilSetting;
518 
519  if(!$ilSetting->get('enable_global_profiles'))
520  {
521  return;
522  }
523 
524  // #10827
525  if(substr($a_wsp_id, -4) != "_cll")
526  {
527  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
528  $wsp_id = new ilWorkspaceTree(0);
529  $obj_id = $wsp_id->lookupObjectId($a_wsp_id);
530  $is_wsp = "_wsp";
531  }
532  else
533  {
534  $a_wsp_id = substr($a_wsp_id, 0, -4);
535  $obj_id = ilObject::_lookupObjId($a_wsp_id);
536  $is_wsp = null;
537  }
538  if(!$obj_id)
539  {
540  return;
541  }
542 
543  $blog = new self($obj_id, false);
544  if(!$blog->hasRSS())
545  {
546  return;
547  }
548 
549  include_once "Services/Feeds/classes/class.ilFeedWriter.php";
550  $feed = new ilFeedWriter();
551 
552  include_once "Services/Link/classes/class.ilLink.php";
553  $url = ilLink::_getStaticLink($a_wsp_id, "blog", true, $is_wsp);
554  $url = str_replace("&", "&amp;", $url);
555 
556  // #11870
557  $feed->setChannelTitle(str_replace("&", "&amp;", $blog->getTitle()));
558  $feed->setChannelDescription(str_replace("&", "&amp;", $blog->getDescription()));
559  $feed->setChannelLink($url);
560 
561  // needed for blogpostinggui / pagegui
562  $tpl = new ilTemplate("tpl.main.html", true, true);
563 
564  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
565  include_once("./Modules/Blog/classes/class.ilBlogPostingGUI.php");
566  foreach(ilBlogPosting::getAllPostings($obj_id) as $item)
567  {
568  $id = $item["id"];
569 
570  // only published items
571  $is_active = ilBlogPosting::_lookupActive($id, "blp");
572  if(!$is_active)
573  {
574  continue;
575  }
576 
577  $snippet = strip_tags(ilBlogPostingGUI::getSnippet($id));
578  $snippet = str_replace("&", "&amp;", $snippet);
579 
580  $url = ilLink::_getStaticLink($a_wsp_id, "blog", true, "_".$id.$is_wsp);
581  $url = str_replace("&", "&amp;", $url);
582 
583  $feed_item = new ilFeedItem();
584  $feed_item->setTitle(str_replace("&", "&amp;", $item["title"])); // #16022
585  $feed_item->setDate($item["created"]->get(IL_CAL_DATETIME));
586  $feed_item->setDescription($snippet);
587  $feed_item->setLink($url);
588  $feed_item->setAbout($url);
589  $feed->addItem($feed_item);
590  }
591 
592  $feed->showFeed();
593  exit();
594  }
595 
596  function initDefaultRoles()
597  {
598  global $rbacadmin, $rbacreview, $ilDB;
599 
600  // SET PERMISSION TEMPLATE OF NEW LOCAL CONTRIBUTOR ROLE
601  $set = $ilDB->query("SELECT obj_id FROM object_data ".
602  " WHERE type=".$ilDB->quote("rolt", "text").
603  " AND title=".$ilDB->quote("il_blog_contributor", "text"));
604  $res = $ilDB->fetchAssoc($set);
605  if($res["obj_id"])
606  {
607  $rolf_obj = $this->createRoleFolder();
608 
609  // CREATE ADMIN ROLE
610  $role_obj = $rolf_obj->createRole("il_blog_contributor_".$this->getRefId(),
611  "Contributor of blog obj_no.".$this->getId());
612 
613  $rbacadmin->copyRoleTemplatePermissions($res["obj_id"], ROLE_FOLDER_ID,
614  $rolf_obj->getRefId(), $role_obj->getId());
615 
616  // SET OBJECT PERMISSIONS OF BLOG OBJECT
617  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(), "blog", $rolf_obj->getRefId());
618  $rbacadmin->grantPermission($role_obj->getId(), $ops, $this->getRefId());
619 
620  return true;
621  }
622 
623  return false;
624  }
625 
632  function getLocalContributorRole($a_node_id)
633  {
634  global $rbacreview;
635 
636  foreach($rbacreview->getLocalRoles($a_node_id) as $role_id)
637  {
638  if(substr(ilObject::_lookupTitle($role_id), 0, 19) == "il_blog_contributor")
639  {
640  return $role_id;
641  }
642  }
643  }
644 
645  function getRolesWithContribute($a_node_id)
646  {
647  global $rbacreview;
648 
649  include_once "Services/AccessControl/classes/class.ilObjRole.php";
650 
651  $contr_op_id = ilRbacReview::_getOperationIdByName("contribute");
652  $contr_role_id = $this->getLocalContributorRole($a_node_id);
653 
654  $res = array();
655  foreach($rbacreview->getParentRoleIds($a_node_id) as $role_id => $role)
656  {
657  if($role_id != $contr_role_id &&
658  in_array($contr_op_id, $rbacreview->getActiveOperationsOfRole($a_node_id, $role_id)))
659  {
660  $res[$role_id] = ilObjRole:: _getTranslation($role["title"]);
661  }
662  }
663 
664  return $res;
665  }
666 
667  protected function handleQuotaUpdate()
668  {
669  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
671  $this->getId(),
672  ilUtil::dirsize($this->initStorage($this->getId())),
673  array($this->getId()));
674  }
675 }
676 
677 ?>