ILIAS  Release_4_2_x_branch Revision 61807
 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 
23  function initType()
24  {
25  $this->type = "blog";
26  }
27 
28  protected function doRead()
29  {
30  global $ilDB;
31 
32  $set = $ilDB->query("SELECT * FROM il_blog".
33  " WHERE id = ".$ilDB->quote($this->id, "integer"));
34  $row = $ilDB->fetchAssoc($set);
35  $this->setNotesStatus((bool)$row["notes"]);
36  $this->setProfilePicture((bool)$row["ppic"]);
37  $this->setBackgroundColor($row["bg_color"]);
38  $this->setFontColor($row["font_color"]);
39  $this->setImage($row["img"]);
40  }
41 
42  protected function doCreate()
43  {
44  global $ilDB;
45 
46  $ilDB->manipulate("INSERT INTO il_blog (id,notes,ppic) VALUES (".
47  $ilDB->quote($this->id, "integer").",".
48  $ilDB->quote(true, "integer").",".
49  $ilDB->quote(true, "integer").")");
50  }
51 
52  protected function doDelete()
53  {
54  global $ilDB;
55 
56  $this->deleteImage();
57 
58  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
60 
61  // remove all notifications
62  include_once "./Services/Notification/classes/class.ilNotification.php";
64 
65  $ilDB->manipulate("DELETE FROM il_blog".
66  " WHERE id = ".$ilDB->quote($this->id, "integer"));
67  }
68 
69  protected function doUpdate()
70  {
71  global $ilDB;
72 
73  if($this->id)
74  {
75  $ilDB->manipulate("UPDATE il_blog".
76  " SET notes = ".$ilDB->quote($this->getNotesStatus(), "integer").
77  ",ppic = ".$ilDB->quote($this->hasProfilePicture(), "integer").
78  ",bg_color = ".$ilDB->quote($this->getBackgroundColor(), "text").
79  ",font_color = ".$ilDB->quote($this->getFontcolor(), "text").
80  ",img = ".$ilDB->quote($this->getImage(), "text").
81  " WHERE id = ".$ilDB->quote($this->id, "integer"));
82  }
83  }
84 
90  function getNotesStatus()
91  {
92  return $this->notes;
93  }
94 
100  function setNotesStatus($a_status)
101  {
102  $this->notes = (bool)$a_status;
103  }
104 
110  function hasProfilePicture()
111  {
112  return $this->ppic;
113  }
114 
120  function setProfilePicture($a_status)
121  {
122  $this->ppic = (bool)$a_status;
123  }
124 
131  {
132  if(!$this->bg_color)
133  {
134  $this->bg_color = "ffffff";
135  }
136  return $this->bg_color;
137  }
138 
144  function setBackgroundColor($a_value)
145  {
146  $this->bg_color = (string)$a_value;
147  }
148 
154  function getFontColor()
155  {
156  if(!$this->font_color)
157  {
158  $this->font_color = "505050";
159  }
160  return $this->font_color;
161  }
162 
168  function setFontColor($a_value)
169  {
170  $this->font_color = (string)$a_value;
171  }
172 
178  function getImage()
179  {
180  return $this->img;
181  }
182 
188  function setImage($a_value)
189  {
190  $this->img = (string)$a_value;
191  }
192 
198  function getImageFullPath($a_as_thumb = false)
199  {
200  if($this->img)
201  {
202  $path = $this->initStorage($this->id);
203  if(!$a_as_thumb)
204  {
205  return $path.$this->img;
206  }
207  else
208  {
209  return $path."thb_".$this->img;
210  }
211  }
212  }
213 
217  public function deleteImage()
218  {
219  if($this->id)
220  {
221  include_once "Modules/Blog/classes/class.ilFSStorageBlog.php";
222  $storage = new ilFSStorageBlog($this->id);
223  $storage->delete();
224 
225  $this->setImage(null);
226  }
227  }
228 
236  public static function initStorage($a_id, $a_subdir = null)
237  {
238  include_once "Modules/Blog/classes/class.ilFSStorageBlog.php";
239  $storage = new ilFSStorageBlog($a_id);
240  $storage->create();
241 
242  $path = $storage->getAbsolutePath()."/";
243 
244  if($a_subdir)
245  {
246  $path .= $a_subdir."/";
247 
248  if(!is_dir($path))
249  {
250  mkdir($path);
251  }
252  }
253 
254  return $path;
255  }
256 
263  function uploadImage(array $a_upload)
264  {
265  if(!$this->id)
266  {
267  return false;
268  }
269 
270  $this->deleteImage();
271 
272  // #10074
273  $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $a_upload["name"]);
274 
275  $path = $this->initStorage($this->id);
276  $original = "org_".$this->id."_".$clean_name;
277  $thumb = "thb_".$this->id."_".$clean_name;
278  $processed = $this->id."_".$clean_name;
279 
280  if(@move_uploaded_file($a_upload["tmp_name"], $path.$original))
281  {
282  chmod($path.$original, 0770);
283 
284  $blga_set = new ilSetting("blga");
285  $dimensions = $blga_set->get("banner_width")."x".
286  $blga_set->get("banner_height");
287 
288  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
289  // taking only frame [0] to avoid problems with animated gifs
290  $original_file = ilUtil::escapeShellArg($path.$original);
291  $thumb_file = ilUtil::escapeShellArg($path.$thumb);
292  $processed_file = ilUtil::escapeShellArg($path.$processed);
293  ilUtil::execConvert($original_file."[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
294  ilUtil::execConvert($original_file."[0] -geometry ".$dimensions."! -quality 100 JPEG:".$processed_file);
295 
296  $this->setImage($processed);
297  return true;
298  }
299  return false;
300  }
301 
302  static function sendNotification($a_action, $a_blog_wsp_id, $a_posting_id)
303  {
304  global $ilUser;
305 
306  // get blog object id
307  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
308  $tree = new ilWorkspaceTree($ilUser->getId()); // owner of tree is irrelevant
309  $blog_obj_id = $tree->lookupObjectId($a_blog_wsp_id);
310  if(!$blog_obj_id)
311  {
312  return;
313  }
314  unset($tree);
315 
316 
317  // recipients
318  include_once "./Services/Notification/classes/class.ilNotification.php";
320  $a_blog_wsp_id, $a_posting_id, ($a_action == "comment"));
321  if(!sizeof($users))
322  {
323  return;
324  }
325 
327 
328 
329  // prepare mail content
330 
331  include_once "./Modules/Blog/classes/class.ilBlogPosting.php";
332  $posting = new ilBlogPosting($a_posting_id);
333  $posting_title = $posting->getTitle();
334  $blog_title = ilObject::_lookupTitle($blog_obj_id);
335 
336  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
337  $link = ilWorkspaceAccessHandler::getGotoLink($a_blog_wsp_id, $blog_obj_id, "_".$a_posting_id);
338 
339 
340  // send mails
341 
342  include_once "./Services/Mail/classes/class.ilMail.php";
343  include_once "./Services/User/classes/class.ilObjUser.php";
344  include_once "./Services/Language/classes/class.ilLanguageFactory.php";
345  include_once("./Services/User/classes/class.ilUserUtil.php");
346 
347  $owner = ilObject::_lookupOwner($blog_obj_id);
348 
349  foreach(array_unique($users) as $idx => $user_id)
350  {
351  // the blog owner should only get comments notifications
352  if($a_action != "comment" && $user_id == $owner)
353  {
354  continue;
355  }
356 
357  // the user responsible for the action should not be notified
358  if($user_id != $ilUser->getId())
359  {
360  // use language of recipient to compose message
361  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
362  $ulng->loadLanguageModule('blog');
363 
364  $subject = sprintf($ulng->txt('blog_change_notification_subject'), $blog_title);
365  $message = sprintf($ulng->txt('blog_change_notification_salutation'), ilObjUser::_lookupFullname($user_id))."\n\n";
366 
367  $message .= $ulng->txt('blog_change_notification_body_'.$a_action).":\n\n";
368  $message .= $ulng->txt('obj_blog').": ".$blog_title."\n";
369  $message .= $ulng->txt('blog_posting').": ".$posting_title."\n";
370  $message .= $ulng->txt('blog_changed_by').": ".ilUserUtil::getNamePresentation($ilUser->getId())."\n\n";
371  $message .= $ulng->txt('blog_change_notification_link').": ".$link;
372 
373  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
374  $mail_obj->appendInstallationSignature(true);
375  $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id),
376  "", "", $subject, $message, array(), array("system"));
377  }
378  else
379  {
380  unset($users[$idx]);
381  }
382  }
383  }
384 }
385 
386 ?>