KTrss.inc.php
12.7 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/*
* Created on 08 Jan 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
// boilerplate.
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
require_once(KT_LIB_DIR . "/dispatcher.inc.php");
require_once(KT_LIB_DIR . "/util/ktutil.inc");
require_once(KT_LIB_DIR . "/database/dbutil.inc");
// document related includes
require_once(KT_LIB_DIR . "/documentmanagement/Document.inc");
require_once(KT_LIB_DIR . "/documentmanagement/DocumentType.inc");
require_once(KT_LIB_DIR . "/documentmanagement/DocumentFieldLink.inc");
require_once(KT_LIB_DIR . "/documentmanagement/documentmetadataversion.inc.php");
require_once(KT_LIB_DIR . "/documentmanagement/documentcontentversion.inc.php");
require_once(KT_LIB_DIR . "/metadata/fieldset.inc.php");
require_once(KT_LIB_DIR . "/security/Permission.inc");
// widget includes.
require_once(KT_LIB_DIR . "/widgets/portlet.inc.php");
require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
require_once(KT_LIB_DIR . "/actions/documentaction.inc.php");
require_once(KT_LIB_DIR . "/browse/browseutil.inc.php");
class KTrss{
// Gets a listing of external feeds for user
function getExternalFeedsList($iUserId){
$sQuery = "SELECT id, url, title FROM plugin_rss WHERE user_id = ?";
$aParams = array($iUserId);
$aFeeds = DBUtil::getResultArray(array($sQuery, $aParams));
if (PEAR::isError($aFeeds)) {
// XXX: log error
return false;
}
if ($aFeeds) {
return $aFeeds;
}
}
// Gets full listing of data of documents and folders subscribed to
function getInternalFeed($iUserId){
$aFullList = array_merge(KTrss::getDocuments($iUserId), KTrss::getFolders($iUserId));
if($aFullList){
$internalFeed = KTrss::arrayToXML($aFullList);
$response = rss2arrayBlock($internalFeed);
}
return $response;
}
// Get list of document subscriptions
function getDocumentList($iUserId){
$sQuery = "SELECT document_id as id FROM document_subscriptions WHERE user_id = ?";
$aParams = array($iUserId);
$aDocumentList = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
if (PEAR::isError($aDocumentList)) {
// XXX: log error
return false;
}
if($aDocumentList){
return $aDocumentList;
}
}
// Get list of folder subscriptions
function getFolderList($iUserId){
$sQuery = "SELECT folder_id as id FROM folder_subscriptions WHERE user_id = ?";
$aParams = array($iUserId);
$aFolderList = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
if (PEAR::isError($aFolderList)) {
// XXX: log error
return false;
}
if ($aFolderList) {
return $aFolderList;
}
}
// Get data for all documents subscribed to
function getDocuments($iUserId){
$aDList = KTrss::getDocumentList($iUserId);
if($aDList){
foreach($aDList as $document_id){
$sQuery = "SELECT dt.document_id AS id, dt.datetime AS date, dt.comment AS transaction, dmv.name AS name " .
"FROM document_metadata_version AS dmv, document_subscriptions AS ds, document_transactions AS dt " .
"WHERE dmv.document_id = ds.document_id " .
"AND dt.document_id = ds.document_id " .
"AND ds.document_id = ? " .
"AND ds.user_id = ? " .
"ORDER BY date DESC " .
"LIMIT 1";
$aParams = array($document_id, $iUserId);
$aDocumentsInfo = DBUtil::getResultArray(array($sQuery, $aParams));
$aDocuments[] = $aDocumentsInfo;
}
}
if (PEAR::isError($aDocuments)) {
// XXX: log error
return false;
}
if ($aDocuments) {
return $aDocuments;
}
}
// Get data for all folders subscribed to
function getFolders($iUserId){
$aFList = KTrss::getFolderList($iUserId);
if($aFList){
foreach($aFList as $folder_id){
$sQuery = "SELECT ft.folder_id AS id, ft.datetime AS date, ft.comment AS transaction, f.name AS name " .
"FROM folders AS f, folder_subscriptions AS fs, folder_transactions AS ft " .
"WHERE f.id = fs.folder_id " .
"AND ft.folder_id = fs.folder_id " .
"AND fs.folder_id = ? " .
"AND fs.user_id = ? " .
"ORDER BY date DESC " .
"LIMIT 1";
$aParams = array($folder_id, $iUserId);
$aFoldersInfo = DBUtil::getResultArray(array($sQuery, $aParams));
if($aFoldersInfo){
$aFolders[] = $aFoldersInfo;
}
}
}
if (PEAR::isError($aFolders)) {
// XXX: log error
return false;
}
if ($aFolders){
return $aFolders;
}
}
function getOneDocument($iDocumentId){
$sQuery = "SELECT dt.document_id AS id, dt.datetime AS date, dt.comment AS transaction, dmv.name AS name " .
"FROM document_metadata_version AS dmv, document_transactions AS dt " .
"WHERE dmv.document_id = dt.document_id " .
"AND dt.document_id = ? " .
"ORDER BY date DESC ";
$aParams = array($iDocumentId);
$aDocumentInfo = DBUtil::getResultArray(array($sQuery, $aParams));
if($aDocumentInfo){
$aDocuments[] = $aDocumentInfo;
}
if (PEAR::isError($aDocumentInfo)) {
return false;
}
if ($aDocuments){
return $aDocuments;
}
}
function getOneFolder($iFolderId){
$sQuery = "SELECT ft.folder_id AS id, ft.datetime AS date, ft.comment AS transaction, f.name AS name " .
"FROM folders AS f, folder_transactions AS ft " .
"WHERE ft.folder_id = f.id " .
"AND f.id = ? " .
"ORDER BY date DESC " .
"LIMIT 1";
$aParams = array($iFolderId);
$aFoldersInfo = DBUtil::getResultArray(array($sQuery, $aParams));
if($aFoldersInfo){
$aFolders[] = $aFoldersInfo;
}
if (PEAR::isError($aFoldersInfo)) {
// XXX: log error
return false;
}
if ($aFolders){
return $aFolders;
}
}
// Takes in an array as a parameter and returns rss2.0 compatible xml
function arrayToXML($aItems){
// Build path to host
$aPath = explode('/', trim($_SERVER['PHP_SELF']));
$hostPath = "http://".$_SERVER['HTTP_HOST']."/".$aPath[1]."/";
$feed = "<?xml version=\"1.0\"?>\n";
$feed .= "<rss version=\"2.0\">\n".
"<channel>\n" .
"<title>KnowledgeTree RSS</title>\n" .
"<copyright>(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7</copyright>\n" .
"<link>".$hostPath."</link>\n" .
"<description>KT-RSS</description>\n" .
"<image>\n".
"<title>KNowledgeTree RSS</title>\n".
"<width>140</width>\n".
"<height>28</height>".
"<link>".$hostPath."knowledgeTree/</link>\n".
"<url>".$hostPath."resources/graphics/ktlogo_rss.png</url>\n".
"</image>\n";
foreach($aItems as $item){
$feed .= "<item>" .
"<title>".$item[0]['name']."</title>\n" .
"<link>".$hostPath."view.php?fDocumentId=".$item[0]['id']."</link>\n" .
"<description>".$item[0]['transaction']."</description>\n".
"</item>\n";
}
$feed .= "</channel>\n" .
"</rss>\n";
return $feed;
}
// Takes in an array as a parameter and returns rss 2.0 compatible xml
function arrayToXMLSingle($aItems){
// Build path to host
$aPath = explode('/', trim($_SERVER['PHP_SELF']));
$hostPath = "http://".$_SERVER['HTTP_HOST']."/".$aPath[1]."/";
$feed = "<?xml version=\"1.0\"?>\n";
$feed .= "<rss version=\"2.0\">\n".
"<channel>\n" .
"<title>KnowledgeTree RSS</title>\n" .
"<copyright>(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7</copyright>\n" .
"<link>".$hostPath."</link>\n" .
"<description>KT-RSS</description>\n" .
"<image>\n".
"<title>KNowledgeTree RSS</title>\n".
"<width>140</width>\n".
"<height>28</height>".
"<link>".$hostPath."knowledgeTree/</link>\n".
"<url>".$hostPath."resources/graphics/ktlogo_rss.png</url>\n".
"</image>\n";
foreach($aItems as $item){
$feed .= "<item>" .
"<title>".$item[0]['name']."</title>\n" .
"<link>".$hostPath."view.php?fDocumentId=".$item[0]['id']."</link>\n" .
"<description>".$item[0]['transaction']."</description>\n".
"</item>\n";
}
$feed .= "</channel>\n" .
"</rss>\n";
return $feed;
}
// Delete feed function
function deleteFeed($iFeedId){
$res = DBUtil::autoDelete('plugin_rss', $iFeedId);
}
// Get title for external feed
function getExternalFeedTitle($iFeedId){
$sQuery = "SELECT title FROM plugin_rss WHERE id = ?";
$aParams = array($iFeedId);
$sFeedTitle = DBUtil::getOneResultKey(array($sQuery, $aParams), 'title');
if (PEAR::isError($sFeedTitle)) {
// XXX: log error
return false;
}
if ($sFeedTitle) {
return $sFeedTitle;
}
}
// Get url for external feed
function getExternalFeedUrl($iFeedId){
$sQuery = "SELECT url FROM plugin_rss WHERE id = ?";
$aParams = array($iFeedId);
$sFeedUrl = DBUtil::getOneResultKey(array($sQuery, $aParams), 'url');
if (PEAR::isError($sFeedUrl)) {
// XXX: log error
return false;
}
if ($sFeedUrl) {
return $sFeedUrl;
}
}
// Update external feed data
function updateFeed($iFeedId, $sFeedTitle, $sFeedUrl){
$sQuery = "UPDATE plugin_rss SET title=?, url=? WHERE id=?";
$aParams = array($sFeedTitle, $sFeedUrl, $iFeedId);
$res = DBUtil::runQuery(array($sQuery, $aParams));
return $res;
}
// Create new external feed
function createFeed($sFeedTitle, $sFeedUrl, $iUserId){
$aParams = array(
'user_id' => $iUserId,
'url' => $sFeedUrl,
'title' => $sFeedTitle,
);
$res = DBUtil::autoInsert('plugin_rss', $aParams);
return $res;
}
// Should be removed...not being used anywhere
function authenticateFolder($iUserId, $iFolderId){
$aFList = KTrss::getFolderList($iUserId);
$result = false;
if($aFList){
foreach($aFList as $folder_id){
if($folder_id == $iFolderId){
$result = true;
}
}
}
return $result;
}
// Should be removed...not being used anywhere
function authenticateDocument($iUserId ,$iDocumentId){
$aDList = KTrss::getDocumentList($iUserId);
$result = false;
if($aDList){
foreach($aDList as $document_id){
if($document_id == $iDocumentId){
$result = true;
}
}
}
return $result;
}
// Function to validate that a user has permissions for a specific document
function validateDocumentPermissions($iUserId, $iDocumentId){
// check if user id is in session. If not, set it
if(!isset($_SESSION["userID"])){
$_SESSION['userID'] = $iUserId;
}
// get document object
$oDocument =& Document::get($iDocumentId);
if (PEAR::isError($oDocument)) {
return false;
}
// check permissions for document
if(Permission::userHasDocumentReadPermission($oDocument)){
return true;
}else{
return false;
}
}
// Function to validate that a user has permissions for a specific folder
function validateFolderPermissions($iUserId, $iFolderId){
// check if user id is in session. If not, set it
if(!isset($_SESSION["userID"])){
$_SESSION['userID'] = $iUserId;
}
// get folder object
$oFolder = Folder::get($iFolderId);
if (PEAR::isError($oFolder)) {
return false;
}
// check permissions for folder
if(Permission::userHasFolderReadPermission($oFolder)){
return true;
}else{
return false;
}
}
}
?>