diff --git a/plugins/rssplugin/KTrss.inc.php b/plugins/rssplugin/KTrss.inc.php index c1b1f2b..10fd72e 100644 --- a/plugins/rssplugin/KTrss.inc.php +++ b/plugins/rssplugin/KTrss.inc.php @@ -6,7 +6,30 @@ * Window - Preferences - PHPeclipse - PHP - Code Templates */ -class KTrss extends KTEntity { +// 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 = ?"; @@ -107,7 +130,6 @@ class KTrss extends KTEntity { if($aFoldersInfo){ $aFolders[] = $aFoldersInfo; } - } } if (PEAR::isError($aFolders)) { @@ -119,34 +141,106 @@ class KTrss extends KTEntity { } } + 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 = ""; - $feed .= "". - "" . - "KnowledgeTree RSS" . - "(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7" . - "".$hostPath."" . - "KT-RSS" . - "". - "KNowledgeTree RSS". - "140". + $feed = "\n"; + $feed .= "\n". + "\n" . + "KnowledgeTree RSS\n" . + "(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7\n" . + "".$hostPath."\n" . + "KT-RSS\n" . + "\n". + "KNowledgeTree RSS\n". + "140\n". "28". - "".$hostPath."knowledgeTree/". - "".$hostPath."resources/graphics/ktlogo_rss.png". - ""; + "".$hostPath."knowledgeTree/\n". + "".$hostPath."resources/graphics/ktlogo_rss.png\n". + "\n"; foreach($aItems as $item){ $feed .= "" . - "".$item[0]['name']."" . - "".$hostPath."view.php?fDocumentId=".$item[0]['id']."" . - "".$item[0]['transaction']."". - ""; + "".$item[0]['name']."\n" . + "".$hostPath."view.php?fDocumentId=".$item[0]['id']."\n" . + "".$item[0]['transaction']."\n". + "\n"; } - $feed .= "" . - ""; + $feed .= "\n" . + "\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 = "\n"; + $feed .= "\n". + "\n" . + "KnowledgeTree RSS\n" . + "(c) 2006 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved - KnowledgeTree Version: OSS 3.3 beta 7\n" . + "".$hostPath."\n" . + "KT-RSS\n" . + "\n". + "KNowledgeTree RSS\n". + "140\n". + "28". + "".$hostPath."knowledgeTree/\n". + "".$hostPath."resources/graphics/ktlogo_rss.png\n". + "\n"; + foreach($aItems as $item){ + $feed .= "" . + "".$item[0]['name']."\n" . + "".$hostPath."view.php?fDocumentId=".$item[0]['id']."\n" . + "".$item[0]['transaction']."\n". + "\n"; + } + $feed .= "\n" . + "\n"; return $feed; } @@ -206,5 +300,75 @@ class KTrss extends KTEntity { 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; + } + } } ?> diff --git a/plugins/rssplugin/RSSDocumentLinkAction.php b/plugins/rssplugin/RSSDocumentLinkAction.php new file mode 100644 index 0000000..6893b79 --- /dev/null +++ b/plugins/rssplugin/RSSDocumentLinkAction.php @@ -0,0 +1,31 @@ +oDocument; + + // get document id + $iFId = $oDocument->getID(); + + // return link...there MIGHT be a nicer way of doing this? + return "RSS"; + } +} +?> \ No newline at end of file diff --git a/plugins/rssplugin/RSSFolderLinkAction.php b/plugins/rssplugin/RSSFolderLinkAction.php new file mode 100644 index 0000000..d364cba --- /dev/null +++ b/plugins/rssplugin/RSSFolderLinkAction.php @@ -0,0 +1,31 @@ +oFolder; + + // get folder id + $iFId = $oFolder->getID(); + + // return link...there MIGHT be a nicer way of doing this? + return "RSS"; + } +} +?> \ No newline at end of file diff --git a/plugins/rssplugin/RSSPlugin.php b/plugins/rssplugin/RSSPlugin.php index 8fdf7bd..400e807 100644 --- a/plugins/rssplugin/RSSPlugin.php +++ b/plugins/rssplugin/RSSPlugin.php @@ -9,6 +9,8 @@ require_once(KT_LIB_DIR . "/plugins/plugin.inc.php"); require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php"); require_once('manageRSSFeeds.php'); +require_once('RSSFolderLinkAction.php'); +require_once('RSSDocumentLinkAction.php'); class RSSPlugin extends KTPlugin @@ -23,6 +25,8 @@ require_once('manageRSSFeeds.php'); } function setup() { + $this->registerAction('folderaction', 'RSSFolderLinkAction', 'ktcore.rss.plugin.folder.link', $sFilename = null); + $this->registerAction('documentaction', 'RSSDocumentLinkAction', 'ktcore.rss.document.plugin', $sFilename = null); $this->registerDashlet('RSSDashlet', 'ktcore.rss.feed.dashlet', 'RSSDashlet.php'); $this->registerPage('managerssfeeds', 'ManageRSSFeedsDispatcher'); diff --git a/resources/graphics/rss.gif b/resources/graphics/rss.gif new file mode 100644 index 0000000..f434ea9 --- /dev/null +++ b/resources/graphics/rss.gif