Commit b90ba449d387b432342268379c42a84f563d024b
1 parent
7918d5f3
KTS-1624
"Allow user to subscribe to rss feed for documents and folders" Implemented. Reviewed By: Kevin git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6171 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
251 additions
and
21 deletions
plugins/rssplugin/KTrss.inc.php
| ... | ... | @@ -6,7 +6,30 @@ |
| 6 | 6 | * Window - Preferences - PHPeclipse - PHP - Code Templates |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class KTrss extends KTEntity { | |
| 9 | +// boilerplate. | |
| 10 | +require_once(KT_LIB_DIR . "/templating/templating.inc.php"); | |
| 11 | +require_once(KT_LIB_DIR . "/templating/kt3template.inc.php"); | |
| 12 | +require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | |
| 13 | +require_once(KT_LIB_DIR . "/util/ktutil.inc"); | |
| 14 | +require_once(KT_LIB_DIR . "/database/dbutil.inc"); | |
| 15 | + | |
| 16 | +// document related includes | |
| 17 | +require_once(KT_LIB_DIR . "/documentmanagement/Document.inc"); | |
| 18 | +require_once(KT_LIB_DIR . "/documentmanagement/DocumentType.inc"); | |
| 19 | +require_once(KT_LIB_DIR . "/documentmanagement/DocumentFieldLink.inc"); | |
| 20 | +require_once(KT_LIB_DIR . "/documentmanagement/documentmetadataversion.inc.php"); | |
| 21 | +require_once(KT_LIB_DIR . "/documentmanagement/documentcontentversion.inc.php"); | |
| 22 | +require_once(KT_LIB_DIR . "/metadata/fieldset.inc.php"); | |
| 23 | +require_once(KT_LIB_DIR . "/security/Permission.inc"); | |
| 24 | + | |
| 25 | +// widget includes. | |
| 26 | +require_once(KT_LIB_DIR . "/widgets/portlet.inc.php"); | |
| 27 | +require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php"); | |
| 28 | +require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php"); | |
| 29 | +require_once(KT_LIB_DIR . "/actions/documentaction.inc.php"); | |
| 30 | +require_once(KT_LIB_DIR . "/browse/browseutil.inc.php"); | |
| 31 | + | |
| 32 | +class KTrss{ | |
| 10 | 33 | // Gets a listing of external feeds for user |
| 11 | 34 | function getExternalFeedsList($iUserId){ |
| 12 | 35 | $sQuery = "SELECT id, url, title FROM plugin_rss WHERE user_id = ?"; |
| ... | ... | @@ -107,7 +130,6 @@ class KTrss extends KTEntity { |
| 107 | 130 | if($aFoldersInfo){ |
| 108 | 131 | $aFolders[] = $aFoldersInfo; |
| 109 | 132 | } |
| 110 | - | |
| 111 | 133 | } |
| 112 | 134 | } |
| 113 | 135 | if (PEAR::isError($aFolders)) { |
| ... | ... | @@ -119,34 +141,106 @@ class KTrss extends KTEntity { |
| 119 | 141 | } |
| 120 | 142 | } |
| 121 | 143 | |
| 144 | + function getOneDocument($iDocumentId){ | |
| 145 | + $sQuery = "SELECT dt.document_id AS id, dt.datetime AS date, dt.comment AS transaction, dmv.name AS name " . | |
| 146 | + "FROM document_metadata_version AS dmv, document_transactions AS dt " . | |
| 147 | + "WHERE dmv.document_id = dt.document_id " . | |
| 148 | + "AND dt.document_id = ? " . | |
| 149 | + "ORDER BY date DESC "; | |
| 150 | + $aParams = array($iDocumentId); | |
| 151 | + $aDocumentInfo = DBUtil::getResultArray(array($sQuery, $aParams)); | |
| 152 | + if($aDocumentInfo){ | |
| 153 | + $aDocuments[] = $aDocumentInfo; | |
| 154 | + } | |
| 155 | + if (PEAR::isError($aDocumentInfo)) { | |
| 156 | + return false; | |
| 157 | + } | |
| 158 | + if ($aDocuments){ | |
| 159 | + return $aDocuments; | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 163 | + function getOneFolder($iFolderId){ | |
| 164 | + $sQuery = "SELECT ft.folder_id AS id, ft.datetime AS date, ft.comment AS transaction, f.name AS name " . | |
| 165 | + "FROM folders AS f, folder_transactions AS ft " . | |
| 166 | + "WHERE ft.folder_id = f.id " . | |
| 167 | + "AND f.id = ? " . | |
| 168 | + "ORDER BY date DESC " . | |
| 169 | + "LIMIT 1"; | |
| 170 | + $aParams = array($iFolderId); | |
| 171 | + $aFoldersInfo = DBUtil::getResultArray(array($sQuery, $aParams)); | |
| 172 | + if($aFoldersInfo){ | |
| 173 | + $aFolders[] = $aFoldersInfo; | |
| 174 | + } | |
| 175 | + if (PEAR::isError($aFoldersInfo)) { | |
| 176 | + // XXX: log error | |
| 177 | + return false; | |
| 178 | + } | |
| 179 | + if ($aFolders){ | |
| 180 | + return $aFolders; | |
| 181 | + } | |
| 182 | + } | |
| 183 | + | |
| 122 | 184 | // Takes in an array as a parameter and returns rss2.0 compatible xml |
| 123 | 185 | function arrayToXML($aItems){ |
| 124 | 186 | // Build path to host |
| 125 | 187 | $aPath = explode('/', trim($_SERVER['PHP_SELF'])); |
| 126 | 188 | $hostPath = "http://".$_SERVER['HTTP_HOST']."/".$aPath[1]."/"; |
| 127 | - $feed = "<?xml version=\"1.0\"?>"; | |
| 128 | - $feed .= "<rss version=\"2.0\">". | |
| 129 | - "<channel>" . | |
| 130 | - "<title>KnowledgeTree RSS</title>" . | |
| 131 | - "<copyright>(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7</copyright>" . | |
| 132 | - "<link>".$hostPath."</link>" . | |
| 133 | - "<description>KT-RSS</description>" . | |
| 134 | - "<image>". | |
| 135 | - "<title>KNowledgeTree RSS</title>". | |
| 136 | - "<width>140</width>". | |
| 189 | + $feed = "<?xml version=\"1.0\"?>\n"; | |
| 190 | + $feed .= "<rss version=\"2.0\">\n". | |
| 191 | + "<channel>\n" . | |
| 192 | + "<title>KnowledgeTree RSS</title>\n" . | |
| 193 | + "<copyright>(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7</copyright>\n" . | |
| 194 | + "<link>".$hostPath."</link>\n" . | |
| 195 | + "<description>KT-RSS</description>\n" . | |
| 196 | + "<image>\n". | |
| 197 | + "<title>KNowledgeTree RSS</title>\n". | |
| 198 | + "<width>140</width>\n". | |
| 137 | 199 | "<height>28</height>". |
| 138 | - "<link>".$hostPath."knowledgeTree/</link>". | |
| 139 | - "<url>".$hostPath."resources/graphics/ktlogo_rss.png</url>". | |
| 140 | - "</image>"; | |
| 200 | + "<link>".$hostPath."knowledgeTree/</link>\n". | |
| 201 | + "<url>".$hostPath."resources/graphics/ktlogo_rss.png</url>\n". | |
| 202 | + "</image>\n"; | |
| 141 | 203 | foreach($aItems as $item){ |
| 142 | 204 | $feed .= "<item>" . |
| 143 | - "<title>".$item[0]['name']."</title>" . | |
| 144 | - "<link>".$hostPath."view.php?fDocumentId=".$item[0]['id']."</link>" . | |
| 145 | - "<description>".$item[0]['transaction']."</description>". | |
| 146 | - "</item>"; | |
| 205 | + "<title>".$item[0]['name']."</title>\n" . | |
| 206 | + "<link>".$hostPath."view.php?fDocumentId=".$item[0]['id']."</link>\n" . | |
| 207 | + "<description>".$item[0]['transaction']."</description>\n". | |
| 208 | + "</item>\n"; | |
| 147 | 209 | } |
| 148 | - $feed .= "</channel>" . | |
| 149 | - "</rss>"; | |
| 210 | + $feed .= "</channel>\n" . | |
| 211 | + "</rss>\n"; | |
| 212 | + | |
| 213 | + return $feed; | |
| 214 | + } | |
| 215 | + | |
| 216 | + // Takes in an array as a parameter and returns rss 2.0 compatible xml | |
| 217 | + function arrayToXMLSingle($aItems){ | |
| 218 | + // Build path to host | |
| 219 | + $aPath = explode('/', trim($_SERVER['PHP_SELF'])); | |
| 220 | + $hostPath = "http://".$_SERVER['HTTP_HOST']."/".$aPath[1]."/"; | |
| 221 | + $feed = "<?xml version=\"1.0\"?>\n"; | |
| 222 | + $feed .= "<rss version=\"2.0\">\n". | |
| 223 | + "<channel>\n" . | |
| 224 | + "<title>KnowledgeTree RSS</title>\n" . | |
| 225 | + "<copyright>(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7</copyright>\n" . | |
| 226 | + "<link>".$hostPath."</link>\n" . | |
| 227 | + "<description>KT-RSS</description>\n" . | |
| 228 | + "<image>\n". | |
| 229 | + "<title>KNowledgeTree RSS</title>\n". | |
| 230 | + "<width>140</width>\n". | |
| 231 | + "<height>28</height>". | |
| 232 | + "<link>".$hostPath."knowledgeTree/</link>\n". | |
| 233 | + "<url>".$hostPath."resources/graphics/ktlogo_rss.png</url>\n". | |
| 234 | + "</image>\n"; | |
| 235 | + foreach($aItems as $item){ | |
| 236 | + $feed .= "<item>" . | |
| 237 | + "<title>".$item[0]['name']."</title>\n" . | |
| 238 | + "<link>".$hostPath."view.php?fDocumentId=".$item[0]['id']."</link>\n" . | |
| 239 | + "<description>".$item[0]['transaction']."</description>\n". | |
| 240 | + "</item>\n"; | |
| 241 | + } | |
| 242 | + $feed .= "</channel>\n" . | |
| 243 | + "</rss>\n"; | |
| 150 | 244 | |
| 151 | 245 | return $feed; |
| 152 | 246 | } |
| ... | ... | @@ -206,5 +300,75 @@ class KTrss extends KTEntity { |
| 206 | 300 | |
| 207 | 301 | return $res; |
| 208 | 302 | } |
| 303 | + | |
| 304 | + // Should be removed...not being used anywhere | |
| 305 | + function authenticateFolder($iUserId, $iFolderId){ | |
| 306 | + $aFList = KTrss::getFolderList($iUserId); | |
| 307 | + $result = false; | |
| 308 | + if($aFList){ | |
| 309 | + foreach($aFList as $folder_id){ | |
| 310 | + if($folder_id == $iFolderId){ | |
| 311 | + $result = true; | |
| 312 | + } | |
| 313 | + } | |
| 314 | + } | |
| 315 | + | |
| 316 | + return $result; | |
| 317 | + } | |
| 318 | + | |
| 319 | + // Should be removed...not being used anywhere | |
| 320 | + function authenticateDocument($iUserId ,$iDocumentId){ | |
| 321 | + $aDList = KTrss::getDocumentList($iUserId); | |
| 322 | + $result = false; | |
| 323 | + if($aDList){ | |
| 324 | + foreach($aDList as $document_id){ | |
| 325 | + if($document_id == $iDocumentId){ | |
| 326 | + $result = true; | |
| 327 | + } | |
| 328 | + } | |
| 329 | + } | |
| 330 | + | |
| 331 | + return $result; | |
| 332 | + } | |
| 333 | + | |
| 334 | + // Function to validate that a user has permissions for a specific document | |
| 335 | + function validateDocumentPermissions($iUserId, $iDocumentId){ | |
| 336 | + // check if user id is in session. If not, set it | |
| 337 | + if(!isset($_SESSION["userID"])){ | |
| 338 | + $_SESSION['userID'] = $iUserId; | |
| 339 | + } | |
| 340 | + // get document object | |
| 341 | + $oDocument =& Document::get($iDocumentId); | |
| 342 | + if (PEAR::isError($oDocument)) { | |
| 343 | + return false; | |
| 344 | + } | |
| 345 | + | |
| 346 | + // check permissions for document | |
| 347 | + if(Permission::userHasDocumentReadPermission($oDocument)){ | |
| 348 | + return true; | |
| 349 | + }else{ | |
| 350 | + return false; | |
| 351 | + } | |
| 352 | + } | |
| 353 | + | |
| 354 | + // Function to validate that a user has permissions for a specific folder | |
| 355 | + function validateFolderPermissions($iUserId, $iFolderId){ | |
| 356 | + // check if user id is in session. If not, set it | |
| 357 | + if(!isset($_SESSION["userID"])){ | |
| 358 | + $_SESSION['userID'] = $iUserId; | |
| 359 | + } | |
| 360 | + // get folder object | |
| 361 | + $oFolder = Folder::get($iFolderId); | |
| 362 | + if (PEAR::isError($oFolder)) { | |
| 363 | + return false; | |
| 364 | + } | |
| 365 | + | |
| 366 | + // check permissions for folder | |
| 367 | + if(Permission::userHasFolderReadPermission($oFolder)){ | |
| 368 | + return true; | |
| 369 | + }else{ | |
| 370 | + return false; | |
| 371 | + } | |
| 372 | + } | |
| 209 | 373 | } |
| 210 | 374 | ?> | ... | ... |
plugins/rssplugin/RSSDocumentLinkAction.php
0 โ 100644
| 1 | +<?php | |
| 2 | +require_once(KT_LIB_DIR . '/actions/folderaction.inc.php'); | |
| 3 | +require_once(KT_LIB_DIR . '/permissions/permission.inc.php'); | |
| 4 | +require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); | |
| 5 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | |
| 6 | + | |
| 7 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 8 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 9 | + | |
| 10 | +require_once(KT_LIB_DIR . '/roles/Role.inc'); | |
| 11 | + | |
| 12 | +class RSSDocumentLinkAction extends KTDocumentAction { | |
| 13 | + var $sName = 'ktcore.rss.plugin.document.link'; | |
| 14 | + var $_sShowPermission = "ktcore.permissions.read"; | |
| 15 | + var $sDisplayName = "RSS"; | |
| 16 | + | |
| 17 | + function getDisplayName() { | |
| 18 | + // built server path | |
| 19 | + $hostPath = "http://".$_SERVER['HTTP_HOST']."/".$GLOBALS['KTRootUrl']."/"; | |
| 20 | + | |
| 21 | + //get document object | |
| 22 | + $oDocument = $this->oDocument; | |
| 23 | + | |
| 24 | + // get document id | |
| 25 | + $iFId = $oDocument->getID(); | |
| 26 | + | |
| 27 | + // return link...there MIGHT be a nicer way of doing this? | |
| 28 | + return "<a href='".KTBrowseUtil::buildBaseUrl('rss')."?folderId=".$iFId."' target='_blank'><img src='".$hostPath."resources/graphics/rss.gif' alt='RSS' border=0/></a>"; | |
| 29 | + } | |
| 30 | +} | |
| 31 | +?> | |
| 0 | 32 | \ No newline at end of file | ... | ... |
plugins/rssplugin/RSSFolderLinkAction.php
0 โ 100644
| 1 | +<?php | |
| 2 | +require_once(KT_LIB_DIR . '/actions/folderaction.inc.php'); | |
| 3 | +require_once(KT_LIB_DIR . '/permissions/permission.inc.php'); | |
| 4 | +require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); | |
| 5 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | |
| 6 | + | |
| 7 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 8 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 9 | + | |
| 10 | +require_once(KT_LIB_DIR . '/roles/Role.inc'); | |
| 11 | + | |
| 12 | +class RSSFolderLinkAction extends KTFolderAction { | |
| 13 | + var $sName = 'ktcore.rss.plugin.folder.link'; | |
| 14 | + var $_sShowPermission = "ktcore.permissions.read"; | |
| 15 | + var $sDisplayName = "RSS"; | |
| 16 | + | |
| 17 | + function getDisplayName() { | |
| 18 | + // built server path | |
| 19 | + $hostPath = "http://".$_SERVER['HTTP_HOST']."/".$GLOBALS['KTRootUrl']."/"; | |
| 20 | + | |
| 21 | + //get folder object | |
| 22 | + $oFolder = $this->oFolder; | |
| 23 | + | |
| 24 | + // get folder id | |
| 25 | + $iFId = $oFolder->getID(); | |
| 26 | + | |
| 27 | + // return link...there MIGHT be a nicer way of doing this? | |
| 28 | + return "<a href='".KTBrowseUtil::buildBaseUrl('rss')."?folderId=".$iFId."'><img src='".$hostPath."resources/graphics/rss.gif' alt='RSS' border=0/></a>"; | |
| 29 | + } | |
| 30 | +} | |
| 31 | +?> | |
| 0 | 32 | \ No newline at end of file | ... | ... |
plugins/rssplugin/RSSPlugin.php
| ... | ... | @@ -9,6 +9,8 @@ |
| 9 | 9 | require_once(KT_LIB_DIR . "/plugins/plugin.inc.php"); |
| 10 | 10 | require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php"); |
| 11 | 11 | require_once('manageRSSFeeds.php'); |
| 12 | +require_once('RSSFolderLinkAction.php'); | |
| 13 | +require_once('RSSDocumentLinkAction.php'); | |
| 12 | 14 | |
| 13 | 15 | |
| 14 | 16 | class RSSPlugin extends KTPlugin |
| ... | ... | @@ -23,6 +25,8 @@ require_once('manageRSSFeeds.php'); |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | function setup() { |
| 28 | + $this->registerAction('folderaction', 'RSSFolderLinkAction', 'ktcore.rss.plugin.folder.link', $sFilename = null); | |
| 29 | + $this->registerAction('documentaction', 'RSSDocumentLinkAction', 'ktcore.rss.document.plugin', $sFilename = null); | |
| 26 | 30 | $this->registerDashlet('RSSDashlet', 'ktcore.rss.feed.dashlet', 'RSSDashlet.php'); |
| 27 | 31 | $this->registerPage('managerssfeeds', 'ManageRSSFeedsDispatcher'); |
| 28 | 32 | ... | ... |
resources/graphics/rss.gif
0 โ 100644
456 Bytes