ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilObjBlog.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
24class ilObjBlog extends ilObject2
25{
26 public const NAV_MODE_LIST = 1;
27 public const NAV_MODE_MONTH = 2;
29 public const ABSTRACT_DEFAULT_IMAGE_WIDTH = 144;
32 protected ?Settings $blog_settings = null;
34 protected \ILIAS\Style\Content\DomainService $content_style_domain;
35 protected \ILIAS\Notes\Service $notes_service;
36
37 protected bool $notes = false;
38 protected bool $style = false;
39
40 public function __construct(
41 int $a_id = 0,
42 bool $a_reference = true
43 ) {
44 global $DIC;
45
46 $this->notes_service = $DIC->notes();
47 $this->settings_manager = $DIC->blog()->internal()->domain()->blogSettings();
48
49 parent::__construct($a_id, $a_reference);
50 $this->rbac_review = $DIC->rbac()->review();
51
52 $this->content_style_domain = $DIC
53 ->contentStyle()
54 ->domain();
55
56 if ($this->getId() > 0) {
57 $this->blog_settings = $this->settings_manager->getByObjId($this->getId());
58 }
59 }
60
61 protected function initType(): void
62 {
63 $this->type = "blog";
64 }
65
66 protected function doRead(): void
67 {
68 // #14661
69 $this->setNotesStatus(
70 $this->notes_service->domain()->commentsActive($this->id)
71 );
72 $this->blog_settings = $this->settings_manager->getByObjId($this->getId());
73 }
74
75 protected function doCreate(bool $clone_mode = false): void
76 {
78
79 $this->createMetaData();
80
81 $ilDB->manipulate("INSERT INTO il_blog (id,ppic,rss_active,approval" .
82 ",abs_shorten,abs_shorten_len,abs_image,abs_img_width,abs_img_height" .
83 ",keywords,authors,nav_mode,nav_list_mon_with_post,ov_post,nav_list_mon) VALUES (" .
84 $ilDB->quote($this->id, "integer") . "," .
85 $ilDB->quote(true, "integer") . "," .
86 $ilDB->quote(true, "integer") . "," .
87 $ilDB->quote(false, "integer") . "," .
88 $ilDB->quote(false, "integer") . "," .
89 $ilDB->quote(0, "integer") . "," .
90 $ilDB->quote(false, "integer") . "," .
91 $ilDB->quote(0, "integer") . "," .
92 $ilDB->quote(0, "integer") . "," .
93 $ilDB->quote(true, "integer") . "," .
94 $ilDB->quote(false, "integer") . "," .
95 $ilDB->quote(self::NAV_MODE_LIST, "integer") . "," .
96 $ilDB->quote(5, "integer") . "," .
97 $ilDB->quote(5, "integer") . "," .
98 $ilDB->quote(5, "integer") .
99 ")");
100
101 // #14661
102 $this->notes_service->domain()->activateComments($this->id);
103 }
104
105 protected function doDelete(): void
106 {
108
109 $this->deleteMetaData();
110
112
113 // remove all notifications
115
116 $ilDB->manipulate("DELETE FROM il_blog" .
117 " WHERE id = " . $ilDB->quote($this->id, "integer"));
118 }
119
120 protected function doUpdate(): void
121 {
122 $this->updateMetaData();
123
124 if ($this->id) {
125 // #14661
126 $this->notes_service->domain()->activateComments(
127 $this->id,
128 $this->getNotesStatus()
129 );
130 }
131 }
132
133 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
134 {
135 assert($new_obj instanceof ilObjBlog);
136
137 $new_obj->setNotesStatus($this->getNotesStatus());
138 $new_obj->update();
139
140 $this->settings_manager->clone($this->getId(), $new_obj->getId());
141
142 // set/copy stylesheet
143 $this->content_style_domain->styleForObjId($this->getId())->cloneTo($new_obj->getId());
144
145 $this->cloneMetaData($new_obj);
146 }
147
148 public function getNotesStatus(): bool
149 {
150 return $this->notes;
151 }
152
153 public function setNotesStatus(bool $a_status): void
154 {
155 $this->notes = $a_status;
156 }
157
158 public static function sendNotification(
159 string $a_action,
160 bool $a_in_wsp,
161 int $a_blog_node_id,
162 int $a_posting_id,
163 ?string $a_comment = null
164 ): void {
165 global $DIC;
166
167 $DIC->blog()->internal()->domain()->notification()->sendNotification(
168 $a_action,
169 $a_in_wsp,
170 $a_blog_node_id,
171 $a_posting_id,
172 $a_comment
173 );
174 }
175
179 public static function deliverRSS(string $a_wsp_id): void
180 {
181 global $DIC;
182
183 $ilSetting = $DIC->settings();
184
185 if (!$ilSetting->get('enable_global_profiles')) {
186 return;
187 }
188
189 // #10827
190 if (!str_ends_with($a_wsp_id, "_cll")) {
191 $wsp_id = new ilWorkspaceTree(0);
192 $obj_id = $wsp_id->lookupObjectId((int) $a_wsp_id);
193 $is_wsp = "_wsp";
194 $pl = $DIC->blog()->internal()->gui()->permanentLink(0, (int) $a_wsp_id);
195 } else {
196 $a_wsp_id = substr($a_wsp_id, 0, -4);
197 $obj_id = ilObject::_lookupObjId((int) $a_wsp_id);
198 $is_wsp = null;
199 $pl = $DIC->blog()->internal()->gui()->permanentLink((int) $a_wsp_id);
200 }
201 if (!$obj_id) {
202 return;
203 }
204
205 $blog_settings = $DIC->blog()->internal()->domain()->blogSettings()
206 ->getByObjId($obj_id);
207 if (!$blog_settings?->getRSS()) {
208 return;
209 }
210
211 $blog = new self($obj_id, false);
212 $feed = new ilFeedWriter();
213
214 $url = $pl->getPermanentLink();
215 $url = str_replace("&", "&amp;", $url);
216
217 // #11870
218 $feed->setChannelTitle(str_replace("&", "&amp;", $blog->getTitle()));
219 $feed->setChannelDescription(str_replace("&", "&amp;", $blog->getDescription()));
220 $feed->setChannelLink($url);
221
222 // needed for blogpostinggui / pagegui
223 $tpl = new ilGlobalTemplate("tpl.main.html", true, true);
224
225 foreach (ilBlogPosting::getAllPostings($obj_id) as $item) {
226 $id = $item["id"];
227
228 // only published items
229 $is_active = ilBlogPosting::_lookupActive($id, "blp");
230 if (!$is_active) {
231 continue;
232 }
233
234 // #16434
235 $snippet = strip_tags(ilBlogPostingGUI::getSnippet($id), "<br><br/><div><p>");
236 $snippet = str_replace("&", "&amp;", $snippet);
237 $snippet = "<![CDATA[" . $snippet . "]]>";
238
239 $url = $pl->getPermanentLink((int) $id);
240 $url = str_replace("&", "&amp;", $url);
241
242 $feed_item = new ilFeedItem();
243 $feed_item->setTitle(str_replace("&", "&amp;", $item["title"])); // #16022
244 $feed_item->setDate($item["created"]->get(IL_CAL_DATETIME));
245 $feed_item->setDescription($snippet);
246 $feed_item->setLink($url);
247 $feed_item->setAbout($url);
248 $feed->addItem($feed_item);
249 }
250
251 $feed->showFeed();
252 exit();
253 }
254
255 public function initDefaultRoles(): void
256 {
258 'il_blog_contributor_' . $this->getRefId(),
259 "Contributor of blog obj_no." . $this->getId(),
260 'il_blog_contributor',
261 $this->getRefId()
262 );
263
265 'il_blog_editor_' . $this->getRefId(),
266 "Editor of blog obj_no." . $this->getId(),
267 'il_blog_editor',
268 $this->getRefId()
269 );
270 }
271
272 public function getLocalContributorRole(int $a_node_id): int
273 {
274 foreach ($this->rbac_review->getLocalRoles($a_node_id) as $role_id) {
275 if (str_starts_with(ilObject::_lookupTitle($role_id), "il_blog_contributor")) {
276 return $role_id;
277 }
278 }
279 return 0;
280 }
281
282 public function getLocalEditorRole(int $a_node_id): int
283 {
284 foreach ($this->rbac_review->getLocalRoles($a_node_id) as $role_id) {
285 if (strpos(ilObject::_lookupTitle($role_id), "il_blog_editor") === 0) {
286 return $role_id;
287 }
288 }
289 return 0;
290 }
291
292 public function getAllLocalRoles(int $a_node_id): array
293 {
294 $res = array();
295 foreach ($this->rbac_review->getLocalRoles($a_node_id) as $role_id) {
297 }
298
299 asort($res);
300 return $res;
301 }
302
303 public function getRolesWithContributeOrRedact(int $a_node_id): array
304 {
305 $contr_op_id = ilRbacReview::_getOperationIdByName("contribute");
306 $redact_op_id = ilRbacReview::_getOperationIdByName("redact");
307 $contr_role_id = $this->getLocalContributorRole($a_node_id);
308 $editor_role_id = $this->getLocalEditorRole($a_node_id);
309
310 $res = array();
311 foreach ($this->rbac_review->getParentRoleIds($a_node_id) as $role_id => $role) {
312 if ($role_id != $contr_role_id &&
313 $role_id != $editor_role_id) {
314 $all_ops = $this->rbac_review->getActiveOperationsOfRole($a_node_id, $role_id);
315 if (in_array($contr_op_id, $all_ops) ||
316 in_array($redact_op_id, $all_ops)) {
317 $res[$role_id] = ilObjRole::_getTranslation($role["title"]);
318 }
319 }
320 }
321
322 return $res;
323 }
324}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_DATETIME
static getSnippet(int $a_id, bool $a_truncate=false, int $a_truncate_length=500, string $a_truncate_sign="...", bool $a_include_picture=false, int $a_picture_width=144, int $a_picture_height=144, ?string $a_export_directory=null)
Get first text paragraph of page.
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
static deleteAllBlogPostings(int $a_blog_id)
Delete all postings for blog.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
static removeForObject(int $type, int $id)
Remove all notifications for given object.
getRolesWithContributeOrRedact(int $a_node_id)
Settings $blog_settings
getLocalEditorRole(int $a_node_id)
getAllLocalRoles(int $a_node_id)
SettingsManager $settings_manager
setNotesStatus(bool $a_status)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
const NAV_MODE_MONTH
ILIAS Style Content DomainService $content_style_domain
__construct(int $a_id=0, bool $a_reference=true)
Constructor.
doCreate(bool $clone_mode=false)
static sendNotification(string $a_action, bool $a_in_wsp, int $a_blog_node_id, int $a_posting_id, ?string $a_comment=null)
const NAV_MODE_LIST
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
getLocalContributorRole(int $a_node_id)
const ABSTRACT_DEFAULT_SHORTEN_LENGTH
const ABSTRACT_DEFAULT_IMAGE_WIDTH
const NAV_MODE_LIST_DEFAULT_POSTINGS
ILIAS Notes Service $notes_service
static deliverRSS(string $a_wsp_id)
Deliver blog as rss feed.
const ABSTRACT_DEFAULT_IMAGE_HEIGHT
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
static _getTranslation(string $a_role_title)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
Copy meta data.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
ilDBInterface $db
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
static _getOperationIdByName(string $a_operation)
get operation id by name of operation
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:70