ILIAS  Release_5_0_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  protected $abstract_shorten = false; // [bool]
27  protected $abstract_image = false; // [bool]
30  protected $keywords = true; // [bool]
31  protected $nav_mode = self::NAV_MODE_LIST; // [int]
33  protected $nav_mode_list_months; // [int]
34  protected $overview_postings; // [int]
35  protected $authors = true; // [bool]
36  protected $order;
37 
38  const NAV_MODE_LIST = 1;
39  const NAV_MODE_MONTH = 2;
40 
45 
46  function initType()
47  {
48  $this->type = "blog";
49  }
50 
51  protected function doRead()
52  {
53  global $ilDB;
54 
55  $set = $ilDB->query("SELECT * FROM il_blog".
56  " WHERE id = ".$ilDB->quote($this->id, "integer"));
57  $row = $ilDB->fetchAssoc($set);
58  $this->setProfilePicture((bool)$row["ppic"]);
59  $this->setBackgroundColor($row["bg_color"]);
60  $this->setFontColor($row["font_color"]);
61  $this->setImage($row["img"]);
62  $this->setRSS($row["rss_active"]);
63  $this->setApproval($row["approval"]);
64  $this->setAbstractShorten($row["abs_shorten"]);
65  $this->setAbstractShortenLength($row["abs_shorten_len"]);
66  $this->setAbstractImage($row["abs_image"]);
67  $this->setAbstractImageWidth($row["abs_img_width"]);
68  $this->setAbstractImageHeight($row["abs_img_height"]);
69  $this->setKeywords($row["keywords"]);
70  $this->setAuthors($row["authors"]);
71  $this->setNavMode($row["nav_mode"]);
72  $this->setNavModeListPostings($row["nav_list_post"]);
73  $this->setNavModeListMonths($row["nav_list_mon"]);
74  $this->setOverviewPostings($row["ov_post"]);
75  if(trim($row["nav_order"]))
76  {
77  $this->setOrder(explode(";", $row["nav_order"]));
78  }
79 
80  // #14661
81  include_once("./Services/Notes/classes/class.ilNote.php");
82  $this->setNotesStatus(ilNote::commentsActivated($this->id, 0, "blog"));
83 
84  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
86  }
87 
88  protected function doCreate()
89  {
90  global $ilDB;
91 
92  $ilDB->manipulate("INSERT INTO il_blog (id,ppic,rss_active,approval".
93  ",abs_shorten,abs_shorten_len,abs_image,abs_img_width,abs_img_height".
94  ",keywords,authors,nav_mode,nav_list_post) VALUES (".
95  $ilDB->quote($this->id, "integer").",".
96  $ilDB->quote(true, "integer").",".
97  $ilDB->quote(true, "integer").",".
98  $ilDB->quote(false, "integer").",".
99  $ilDB->quote($this->hasAbstractShorten(), "integer").",".
100  $ilDB->quote($this->getAbstractShortenLength(), "integer").",".
101  $ilDB->quote($this->hasAbstractImage(), "integer").",".
102  $ilDB->quote($this->getAbstractImageWidth(), "integer").",".
103  $ilDB->quote($this->getAbstractImageHeight(), "integer").",".
104  $ilDB->quote($this->hasKeywords(), "integer").",".
105  $ilDB->quote($this->hasAuthors(), "integer").",".
106  $ilDB->quote($this->getNavMode(), "integer").",".
107  $ilDB->quote($this->getNavModeListPostings(), "integer").
108  ")");
109 
110  // #14661
111  include_once("./Services/Notes/classes/class.ilNote.php");
112  ilNote::activateComments($this->id, 0, "blog", true);
113 
114  /*
115  if ($this->getStyleSheetId() > 0)
116  {
117  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
118  ilObjStyleSheet::writeStyleUsage($this->id, $this->getStyleSheetId());
119  }
120  */
121  }
122 
123  protected function doDelete()
124  {
125  global $ilDB;
126 
127  $this->deleteImage();
128 
129  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
131 
132  // remove all notifications
133  include_once "./Services/Notification/classes/class.ilNotification.php";
135 
136  $ilDB->manipulate("DELETE FROM il_blog".
137  " WHERE id = ".$ilDB->quote($this->id, "integer"));
138  }
139 
140  protected function doUpdate()
141  {
142  global $ilDB;
143 
144  if($this->id)
145  {
146  $ilDB->manipulate("UPDATE il_blog".
147  " SET ppic = ".$ilDB->quote($this->hasProfilePicture(), "integer").
148  ",bg_color = ".$ilDB->quote($this->getBackgroundColor(), "text").
149  ",font_color = ".$ilDB->quote($this->getFontcolor(), "text").
150  ",img = ".$ilDB->quote($this->getImage(), "text").
151  ",rss_active = ".$ilDB->quote($this->hasRSS(), "integer").
152  ",approval = ".$ilDB->quote($this->hasApproval(), "integer").
153  ",abs_shorten = ".$ilDB->quote($this->hasAbstractShorten(), "integer").
154  ",abs_shorten_len = ".$ilDB->quote($this->getAbstractShortenLength(), "integer").
155  ",abs_image = ".$ilDB->quote($this->hasAbstractImage(), "integer").
156  ",abs_img_width = ".$ilDB->quote($this->getAbstractImageWidth(), "integer").
157  ",abs_img_height = ".$ilDB->quote($this->getAbstractImageHeight(), "integer").
158  ",keywords = ".$ilDB->quote($this->hasKeywords(), "integer").
159  ",authors = ".$ilDB->quote($this->hasAuthors(), "integer").
160  ",nav_mode = ".$ilDB->quote($this->getNavMode(), "integer").
161  ",nav_list_post = ".$ilDB->quote($this->getNavModeListPostings(), "integer").
162  ",nav_list_mon = ".$ilDB->quote($this->getNavModeListMonths(), "integer").
163  ",ov_post = ".$ilDB->quote($this->getOverviewPostings(), "integer").
164  ",nav_order = ".$ilDB->quote(implode(";", $this->getOrder()), "text").
165  " WHERE id = ".$ilDB->quote($this->id, "integer"));
166 
167  // #14661
168  include_once("./Services/Notes/classes/class.ilNote.php");
169  ilNote::activateComments($this->id, 0, "blog", $this->getNotesStatus());
170 
171  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
173  }
174  }
175 
176  protected function doCloneObject(ilObjBlog $new_obj, $a_target_id, $a_copy_id = null)
177  {
178  // banner?
179  $img = $this->getImage();
180  if($img)
181  {
182  $new_obj->setImage($img);
183 
184  $source = $this->initStorage($this->getId());
185  $target = $new_obj->initStorage($new_obj->getId());
186 
187  copy($source.$img, $target.$img);
188  }
189 
190  $new_obj->setNotesStatus($this->getNotesStatus());
191  $new_obj->setProfilePicture($this->hasProfilePicture());
192  $new_obj->setBackgroundColor($this->getBackgroundColor());
193  $new_obj->setFontColor($this->getFontColor());
194  $new_obj->setRSS($this->hasRSS());
195  $new_obj->setApproval($this->hasApproval());
196  $new_obj->setAbstractShorten($this->hasAbstractShorten());
198  $new_obj->setAbstractImage($this->hasAbstractImage());
199  $new_obj->setAbstractImageWidth($this->getAbstractImageWidth());
201  $new_obj->update();
202 
203  // set/copy stylesheet
204  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
205  $style_id = $this->getStyleSheetId();
206  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
207  {
208  $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
209  $new_id = $style_obj->ilClone();
210  $new_obj->setStyleSheetId($new_id);
211  $new_obj->update();
212  }
213  }
214 
220  function getNotesStatus()
221  {
222  return $this->notes;
223  }
224 
230  function setNotesStatus($a_status)
231  {
232  $this->notes = (bool)$a_status;
233  }
234 
240  function hasProfilePicture()
241  {
242  return $this->ppic;
243  }
244 
250  function setProfilePicture($a_status)
251  {
252  $this->ppic = (bool)$a_status;
253  }
254 
261  {
262  if(!$this->bg_color)
263  {
264  $this->bg_color = "ffffff";
265  }
266  return $this->bg_color;
267  }
268 
274  function setBackgroundColor($a_value)
275  {
276  $this->bg_color = (string)$a_value;
277  }
278 
284  function getFontColor()
285  {
286  if(!$this->font_color)
287  {
288  $this->font_color = "505050";
289  }
290  return $this->font_color;
291  }
292 
298  function setFontColor($a_value)
299  {
300  $this->font_color = (string)$a_value;
301  }
302 
308  function getImage()
309  {
310  return $this->img;
311  }
312 
318  function setImage($a_value)
319  {
320  $this->img = (string)$a_value;
321  }
322 
328  function getImageFullPath($a_as_thumb = false)
329  {
330  if($this->img)
331  {
332  $path = $this->initStorage($this->id);
333  if(!$a_as_thumb)
334  {
335  return $path.$this->img;
336  }
337  else
338  {
339  return $path."thb_".$this->img;
340  }
341  }
342  }
343 
347  public function deleteImage()
348  {
349  if($this->id)
350  {
351  include_once "Modules/Blog/classes/class.ilFSStorageBlog.php";
352  $storage = new ilFSStorageBlog($this->id);
353  $storage->delete();
354 
355  $this->setImage(null);
356 
357  $this->handleQuotaUpdate();
358  }
359  }
360 
368  public static function initStorage($a_id, $a_subdir = null)
369  {
370  include_once "Modules/Blog/classes/class.ilFSStorageBlog.php";
371  $storage = new ilFSStorageBlog($a_id);
372  $storage->create();
373 
374  $path = $storage->getAbsolutePath()."/";
375 
376  if($a_subdir)
377  {
378  $path .= $a_subdir."/";
379 
380  if(!is_dir($path))
381  {
382  mkdir($path);
383  }
384  }
385 
386  return $path;
387  }
388 
395  function uploadImage(array $a_upload)
396  {
397  if(!$this->id)
398  {
399  return false;
400  }
401 
402  $this->deleteImage();
403 
404  // #10074
405  $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $a_upload["name"]);
406 
407  $path = $this->initStorage($this->id);
408  $original = "org_".$this->id."_".$clean_name;
409  $thumb = "thb_".$this->id."_".$clean_name;
410  $processed = $this->id."_".$clean_name;
411 
412  if(@move_uploaded_file($a_upload["tmp_name"], $path.$original))
413  {
414  chmod($path.$original, 0770);
415 
416  $blga_set = new ilSetting("blga");
417  /* as banner height should overflow, we only handle width
418  $dimensions = $blga_set->get("banner_width")."x".
419  $blga_set->get("banner_height");
420  */
421  $dimensions = $blga_set->get("banner_width");
422 
423  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
424  // taking only frame [0] to avoid problems with animated gifs
425  $original_file = ilUtil::escapeShellArg($path.$original);
426  $thumb_file = ilUtil::escapeShellArg($path.$thumb);
427  $processed_file = ilUtil::escapeShellArg($path.$processed);
428  ilUtil::execConvert($original_file."[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
429  ilUtil::execConvert($original_file."[0] -geometry ".$dimensions." -quality 100 JPEG:".$processed_file);
430 
431  $this->setImage($processed);
432 
433  $this->handleQuotaUpdate();
434 
435  return true;
436  }
437  return false;
438  }
439 
445  function hasRSS()
446  {
447  return $this->rss;
448  }
449 
455  function setRSS($a_status)
456  {
457  $this->rss = (bool)$a_status;
458  }
459 
465  function hasApproval()
466  {
467  return (bool)$this->approval;
468  }
469 
475  function setApproval($a_status)
476  {
477  $this->approval = (bool)$a_status;
478  }
479 
485  function getStyleSheetId()
486  {
487  return (int)$this->style;
488  }
489 
495  function setStyleSheetId($a_style)
496  {
497  $this->style = (int)$a_style;
498  }
499 
501  {
503  }
504 
505  function setAbstractShorten($a_value)
506  {
507  $this->abstract_shorten = (bool)$a_value;
508  }
509 
511  {
513  }
514 
515  function setAbstractShortenLength($a_value)
516  {
517  $this->abstract_shorten_length = (int)$a_value;
518  }
519 
520  function hasAbstractImage()
521  {
522  return $this->abstract_image;
523  }
524 
525  function setAbstractImage($a_value)
526  {
527  $this->abstract_image = (bool)$a_value;
528  }
529 
531  {
533  }
534 
535  function setAbstractImageWidth($a_value)
536  {
537  $this->abstract_image_width = (int)$a_value;
538  }
539 
541  {
543  }
544 
545  function setAbstractImageHeight($a_value)
546  {
547  $this->abstract_image_height = (int)$a_value;
548  }
549 
550  function setKeywords($a_value)
551  {
552  $this->keywords = (bool)$a_value;
553  }
554 
555  function hasKeywords()
556  {
557  return $this->keywords;
558  }
559 
560  function setAuthors($a_value)
561  {
562  $this->authors = (bool)$a_value;
563  }
564 
565  function hasAuthors()
566  {
567  return $this->authors;
568  }
569 
570  function setNavMode($a_value)
571  {
572  $a_value = (int)$a_value;
573  if(in_array($a_value, array(self::NAV_MODE_LIST, self::NAV_MODE_MONTH)))
574  {
575  $this->nav_mode = $a_value;
576  }
577  }
578 
579  function getNavMode()
580  {
581  return $this->nav_mode;
582  }
583 
584  function setNavModeListPostings($a_value)
585  {
586  $this->nav_mode_list_postings = (int)$a_value;
587  }
588 
590  {
592  }
593 
594  function setNavModeListMonths($a_value)
595  {
596  if(!$a_value)
597  {
598  $a_value = null;
599  }
600  else
601  {
602  $a_value = (int)$a_value;
603  }
604  $this->nav_mode_list_months = $a_value;
605  }
606 
608  {
610  }
611 
612  function setOverviewPostings($a_value)
613  {
614  if(!$a_value)
615  {
616  $a_value = null;
617  }
618  else
619  {
620  $a_value = (int)$a_value;
621  }
622  $this->overview_postings = $a_value;
623  }
624 
626  {
628  }
629 
630  function setOrder(array $a_values = null)
631  {
632  $this->order = $a_values;
633  }
634 
635  function getOrder()
636  {
637  return (array)$this->order;
638  }
639 
640  static function sendNotification($a_action, $a_in_wsp, $a_blog_node_id, $a_posting_id, $a_comment = null)
641  {
642  global $ilUser;
643 
644  // get blog object id (repository or workspace)
645  if($a_in_wsp)
646  {
647  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
648  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
649  $tree = new ilWorkspaceTree($ilUser->getId()); // owner of tree is irrelevant
650  $blog_obj_id = $tree->lookupObjectId($a_blog_node_id);
651  $access_handler = new ilWorkspaceAccessHandler($tree);
652  }
653  else
654  {
655  $blog_obj_id = ilObject::_lookupObjId($a_blog_node_id);
656  $access_handler = null;
657  }
658  if(!$blog_obj_id)
659  {
660  return;
661  }
662 
663  include_once "./Modules/Blog/classes/class.ilBlogPosting.php";
664  $posting = new ilBlogPosting($a_posting_id);
665 
666  // #11138
667  $ignore_threshold = ($a_action == "comment");
668 
669  $admin_only = false;
670 
671  // approval handling
672  if(!$posting->isApproved())
673  {
674  $blog = new self($blog_obj_id, false);
675  if($blog->hasApproval())
676  {
677  switch($a_action)
678  {
679  case "update":
680  // un-approved posting was updated - no notifications
681  return;
682 
683  case "new":
684  // un-approved posting was activated - admin-only notification
685  $admin_only = true;
686  $ignore_threshold = true;
687  $a_action = "approve";
688  break;
689  }
690  }
691  }
692 
693  // recipients
694  include_once "./Services/Notification/classes/class.ilNotification.php";
696  $blog_obj_id, $a_posting_id, $ignore_threshold);
697  if(!sizeof($users))
698  {
699  return;
700  }
701 
702  include_once "./Services/Notification/classes/class.ilSystemNotification.php";
703  $ntf = new ilSystemNotification($a_in_wsp);
704  $ntf->setLangModules(array("blog"));
705  $ntf->setRefId($a_blog_node_id);
706  $ntf->setChangedByUserId($ilUser->getId());
707  $ntf->setSubjectLangId('blog_change_notification_subject');
708  $ntf->setIntroductionLangId('blog_change_notification_body_'.$a_action);
709  $ntf->addAdditionalInfo('blog_posting', $posting->getTitle());
710  if($a_comment)
711  {
712  $ntf->addAdditionalInfo('comment', $a_comment, true);
713  }
714  $ntf->setGotoLangId('blog_change_notification_link');
715  $ntf->setReasonLangId('blog_change_notification_reason');
716 
717  $abstract = $posting->getNotificationAbstract();
718  if($abstract)
719  {
720  $ntf->addAdditionalInfo('content', $abstract, true);
721  }
722 
723  $notified = $ntf->sendMail($users, "_".$a_posting_id,
724  ($admin_only ? "write" : "read"));
725 
726  // #14387
727  if(sizeof($notified))
728  {
729  ilNotification::updateNotificationTime(ilNotification::TYPE_BLOG, $blog_obj_id, $notified, $a_posting_id);
730  }
731  }
732 
738  static function deliverRSS($a_wsp_id)
739  {
740  global $tpl, $ilSetting;
741 
742  if(!$ilSetting->get('enable_global_profiles'))
743  {
744  return;
745  }
746 
747  // #10827
748  if(substr($a_wsp_id, -4) != "_cll")
749  {
750  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
751  $wsp_id = new ilWorkspaceTree(0);
752  $obj_id = $wsp_id->lookupObjectId($a_wsp_id);
753  $is_wsp = "_wsp";
754  }
755  else
756  {
757  $a_wsp_id = substr($a_wsp_id, 0, -4);
758  $obj_id = ilObject::_lookupObjId($a_wsp_id);
759  $is_wsp = null;
760  }
761  if(!$obj_id)
762  {
763  return;
764  }
765 
766  $blog = new self($obj_id, false);
767  if(!$blog->hasRSS())
768  {
769  return;
770  }
771 
772  include_once "Services/Feeds/classes/class.ilFeedWriter.php";
773  $feed = new ilFeedWriter();
774 
775  include_once "Services/Link/classes/class.ilLink.php";
776  $url = ilLink::_getStaticLink($a_wsp_id, "blog", true, $is_wsp);
777  $url = str_replace("&", "&amp;", $url);
778 
779  // #11870
780  $feed->setChannelTitle(str_replace("&", "&amp;", $blog->getTitle()));
781  $feed->setChannelDescription(str_replace("&", "&amp;", $blog->getDescription()));
782  $feed->setChannelLink($url);
783 
784  // needed for blogpostinggui / pagegui
785  $tpl = new ilTemplate("tpl.main.html", true, true);
786 
787  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
788  include_once("./Modules/Blog/classes/class.ilBlogPostingGUI.php");
789  foreach(ilBlogPosting::getAllPostings($obj_id) as $item)
790  {
791  $id = $item["id"];
792 
793  // only published items
794  $is_active = ilBlogPosting::_lookupActive($id, "blp");
795  if(!$is_active)
796  {
797  continue;
798  }
799 
800  // #16434
801  $snippet = strip_tags(ilBlogPostingGUI::getSnippet($id), "<br><br/><div><p>");
802  $snippet = str_replace("&", "&amp;", $snippet);
803  $snippet = "<![CDATA[".$snippet."]]>";
804 
805  $url = ilLink::_getStaticLink($a_wsp_id, "blog", true, "_".$id.$is_wsp);
806  $url = str_replace("&", "&amp;", $url);
807 
808  $feed_item = new ilFeedItem();
809  $feed_item->setTitle(str_replace("&", "&amp;", $item["title"])); // #16022
810  $feed_item->setDate($item["created"]->get(IL_CAL_DATETIME));
811  $feed_item->setDescription($snippet);
812  $feed_item->setLink($url);
813  $feed_item->setAbout($url);
814  $feed->addItem($feed_item);
815  }
816 
817  $feed->showFeed();
818  exit();
819  }
820 
821  function initDefaultRoles()
822  {
823  include_once './Services/AccessControl/classes/class.ilObjRole.php';
825  'il_blog_contributor_'.$this->getRefId(),
826  "Contributor of blog obj_no.".$this->getId(),
827  'il_blog_contributor',
828  $this->getRefId()
829  );
830 
831  return array();
832  }
833 
840  function getLocalContributorRole($a_node_id)
841  {
842  global $rbacreview;
843 
844  foreach($rbacreview->getLocalRoles($a_node_id) as $role_id)
845  {
846  if(substr(ilObject::_lookupTitle($role_id), 0, 19) == "il_blog_contributor")
847  {
848  return $role_id;
849  }
850  }
851  }
852 
853  function getRolesWithContribute($a_node_id)
854  {
855  global $rbacreview;
856 
857  include_once "Services/AccessControl/classes/class.ilObjRole.php";
858 
859  $contr_op_id = ilRbacReview::_getOperationIdByName("contribute");
860  $contr_role_id = $this->getLocalContributorRole($a_node_id);
861 
862  $res = array();
863  foreach($rbacreview->getParentRoleIds($a_node_id) as $role_id => $role)
864  {
865  if($role_id != $contr_role_id &&
866  in_array($contr_op_id, $rbacreview->getActiveOperationsOfRole($a_node_id, $role_id)))
867  {
868  $res[$role_id] = ilObjRole:: _getTranslation($role["title"]);
869  }
870  }
871 
872  return $res;
873  }
874 
875  protected function handleQuotaUpdate()
876  {
877  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
879  $this->getId(),
880  ilUtil::dirsize($this->initStorage($this->getId())),
881  array($this->getId()));
882  }
883 }
884 
885 ?>