forked from Krassmus/blubberforum
/
Blubber.class.php
176 lines (160 loc) · 7.59 KB
/
Blubber.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*
* Copyright (c) 2012 Rasmus Fuhse <fuhse@data-quest.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
require_once "lib/classes/UpdateInformation.class.php";
require_once 'lib/datei.inc.php';
require_once dirname(__file__)."/models/ForumPosting.class.php";
require_once dirname(__file__)."/models/BlubberExternalContact.class.php";
if (!function_exists("transformBeforeSave")) {
function transformBeforeSave($text) {
return $text;
}
}
class Blubber extends StudIPPlugin implements StandardPlugin, SystemPlugin {
public $config = array();
public function __construct() {
global $perm;
parent::__construct();
if (UpdateInformation::isCollecting()) {
$data = Request::getArray("page_info");
if (stripos(Request::get("page"), "plugins.php/blubber") !== false) {
$output = array();
$context_id = $data['Blubber']['context_id'];
$stream = $data['Blubber']['stream'];
$last_check = $data['Blubber']['last_check'] ? $data['Blubber']['last_check'] : (time() - 5 * 60);
$parameter = array(
'since' => $last_check
);
if ($stream === "thread") {
$parameter['thread'] = $context_id;
}
if ($stream === "course") {
$parameter['seminar_id'] = $context_id;
}
if ($stream === "profile") {
$parameter['user_id'] = $context_id;
}
if ($data['Blubber']['search']) {
$parameter['search'] = $data['Blubber']['search'];
}
$new_postings = ForumPosting::getPostings($parameter);
$factory = new Flexi_TemplateFactory($this->getPluginPath()."/views");
foreach ($new_postings as $new_posting) {
if ($new_posting['root_id'] === $new_posting['topic_id']) {
$thread = $new_posting;
$template = $factory->open("forum/thread.php");
$template->set_attribute('thread', $new_posting);
} else {
$thread = new ForumPosting($new_posting['root_id']);
$template = $factory->open("forum/comment.php");
$template->set_attribute('posting', $new_posting);
}
ForumPosting::$course_hashes = ($thread['user_id'] !== $thread['Seminar_id'] ? $thread['Seminar_id'] : false);
$template->set_attribute("course_id", $data['Blubber']['seminar_id']);
$output['postings'][] = array(
'posting_id' => $new_posting['topic_id'],
'mkdate' => $new_posting['mkdate'],
'root_id' => $new_posting['root_id'],
'content' => $template->render()
);
}
UpdateInformation::setInformation("Blubber.getNewPosts", $output);
//Events-Queue:
$db = DBManager::get();
$events = $db->query(
"SELECT event_type, item_id " .
"FROM blubber_events_queue " .
"WHERE mkdate >= ".$db->quote($last_check)." " .
"ORDER BY mkdate ASC " .
"")->fetchAll(PDO::FETCH_ASSOC);
UpdateInformation::setInformation("Blubber.blubberEvents", $events);
$db->exec(
"DELETE FROM blubber_events_queue " .
"WHERE mkdate < UNIX_TIMESTAMP() - 60 * 60 * 6 " .
"");
}
}
if (Navigation::hasItem("/course") && $this->isActivated() && version_compare($GLOBALS['SOFTWARE_VERSION'], "2.4") <= 0) {
$tab = new AutoNavigation($this->getDisplayTitle(), PluginEngine::getLink($this, array(), "forum/forum"));
$tab->setImage($this->getPluginURL()."/assets/images/blubber_white.png");
Navigation::addItem("/course/blubberforum", $tab);
}
if (Navigation::hasItem("/community")) {
$nav = new AutoNavigation($this->getDisplayTitle(), PluginEngine::getURL($this, array(), "forum/globalstream"));
Navigation::insertItem("/community/blubber", $nav, "online");
Navigation::getItem("/community")->setURL(PluginEngine::getURL($this, array(), "forum/globalstream"));
}
if (Navigation::hasItem("/profile")) {
$nav = new AutoNavigation(_("Blubber"), PluginEngine::getURL($this, array('user_id' => get_userid(Request::get("username"))), "forum/profile"));
Navigation::addItem("/profile/blubber", $nav);
}
}
public function getTabNavigation($course_id) {
$tab = new AutoNavigation($this->getDisplayTitle(), PluginEngine::getLink($this, array(), "forum/forum"));
$tab->setImage($this->getPluginURL()."/assets/images/blubber_white.png");
return array('blubberforum' => $tab);
}
public function getIconNavigation($course_id, $last_visit, $user_id = null) {
if (!$user_id) {
$user_id = $GLOBALS['user']->id;
}
$icon = new AutoNavigation($this->getDisplayTitle(), PluginEngine::getLink($this, array(), "forum/forum"));
$db = DBManager::get();
$last_own_posting_time = (int) $db->query(
"SELECT mkdate " .
"FROM px_topics " .
"WHERE user_id = ".$db->quote($user_id)." " .
"AND Seminar_id = ".$db->quote($course_id)." " .
"")->fetch(PDO::FETCH_COLUMN, 0);
$new_ones = $db->query(
"SELECT COUNT(*) " .
"FROM px_topics " .
"WHERE chdate > ".$db->quote(max($last_visit, $last_own_posting_time))." " .
"AND user_id != ".$db->quote($user_id)." " .
"AND Seminar_id = ".$db->quote($course_id)." " .
"")->fetch(PDO::FETCH_COLUMN, 0);
if ($new_ones) {
$title = $new_ones > 1 ? sprintf(_("%s neue Blubber"), $new_ones) : _("1 neuer Blubber");
$icon->setImage($this->getPluginURL()."/assets/images/blubber_red.png", array('title' => $title));
$icon->setTitle($title);
} else {
$icon->setImage($this->getPluginURL()."/assets/images/blubber_grey.png", array('title' => $this->getDisplayTitle()));
}
return $icon;
}
public function getNotificationObjects($course_id, $since, $user_id)
{
return array();
}
public function getInfoTemplate($course_id) {
return null;
}
public function getDisplayTitle() {
return "Blubbern";
}
/**
* This method dispatches and displays all actions. It uses the template
* method design pattern, so you may want to implement the methods #route
* and/or #display to adapt to your needs.
*
* @param string the part of the dispatch path, that were not consumed yet
*
* @return void
*/
public function perform($unconsumed_path) {
if(!$unconsumed_path) {
header("Location: " . PluginEngine::getUrl($this), 302);
return false;
}
$trails_root = $this->getPluginPath();
$dispatcher = new Trails_Dispatcher($trails_root, null, 'show');
$dispatcher->current_plugin = $this;
$dispatcher->dispatch($unconsumed_path);
}
}