KTrss.inc.php
6.97 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
<?php
/*
* Created on 08 Jan 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class KTrss extends KTEntity {
// 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;
}
}
// 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\"?>";
$feed .= "<rss version=\"2.0\">".
"<channel>" .
"<title>KnowledgeTree RSS</title>" .
"<copyright>(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7</copyright>" .
"<link>".$hostPath."</link>" .
"<description>KT-RSS</description>" .
"<image>".
"<title>KNowledgeTree RSS</title>".
"<width>140</width>".
"<height>28</height>".
"<link>".$hostPath."knowledgeTree/</link>".
"<url>".$hostPath."resources/graphics/ktlogo_rss.png</url>".
"</image>";
foreach($aItems as $item){
$feed .= "<item>" .
"<title>".$item[0]['name']."</title>" .
"<link>".$hostPath."view.php?fDocumentId=".$item[0]['id']."</link>" .
"<description>".$item[0]['transaction']."</description>".
"</item>";
}
$feed .= "</channel>" .
"</rss>";
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;
}
}
?>