⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subscriptions.inc.php.svn-base

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
<?php/** * $Id$ * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * * * ------------------------------------------------------------------------- * * Subscription notification type. * * To use this, instantiate a SubscriptionEvent, and call the * appropriate "event" method. * */require_once(KT_LIB_DIR . "/database/dbutil.inc");require_once(KT_LIB_DIR . "/subscriptions/Subscription.inc");require_once(KT_LIB_DIR . "/users/User.inc");require_once(KT_LIB_DIR . "/dashboard/Notification.inc.php");require_once(KT_LIB_DIR . "/alert/delivery/EmailAlert.inc");require_once(KT_LIB_DIR . "/templating/templating.inc.php");class SubscriptionEvent {    var $eventTypes = array(        "AddFolder",        "RemoveSubscribedFolder",        "RemoveChildFolder",        "AddDocument",        "RemoveSubscribedDocument",        "RemoveChildDocument",        "ModifyDocument",        "CheckInDocument",        "CheckOutDocument",        "MovedDocument",        "CopiedDocument",        "ArchivedDocument",        "RestoredArchivedDocument",        "DownloadDocument",    );    var $subscriptionTypes = array(        "Document" => 1,        "Folder" => 2,    );	function &subTypes($sType) {	    $subscriptionTypes = array(            "Document" => 1,            "Folder" => 2,		);		return KTUtil::arrayGet($subscriptionTypes, $sType, null);	}    var $alertedUsers = array();       // per-instance (e.g. per-event) list of users who were contacted.    var $_parameters = array();        // internal storage for    var $child = -1;                   // the child object-id (e.g. which initiated the event: document OR folder)    var $parent = -1;                  // the folder-id of the parent    // FIXME stubs.    /* Each of these functions handles appropriate propogation (e.g. both     * folder and document subscription) without calling secondary functions.     * Every attempt is made to be as explicit as possible.     */    // alerts users who are subscribed to $iParentFolderId.    function AddFolder($oAddedFolder, $oParentFolder) {        $content = new SubscriptionContent(); // needed for i18n	    // only useful for folder subscriptions.        $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'AddFolder', $oAddedFolder->getName(), $oAddedFolder->getId(), $parentId);    }    function AddDocument ($oAddedDocument, $oParentFolder) {        $content = new SubscriptionContent(); // needed for i18n	    // two parts to this:        $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'AddDocument', $oAddedDocument->getName(), $oAddedDocument->getId(), $parentId);    }    function RemoveFolder($oRemovedFolder, $oParentFolder) {        $content = new SubscriptionContent(); // needed for i18n	    // two cases to consider here:		//    - notify people who are subscribed to the parent folder.		//    - notify and unsubscribe people who are subscribed to the actual folder.		// we need to start with the latter, so we don't "lose" any.		$aUsers = $this->_getSubscribers($oRemovedFolder->getId(), $this->subscriptionTypes["Folder"]);		foreach ($aUsers as $oSubscriber) {		    // notification object first.			$aNotificationOptions = array();			$aNotificationOptions['target_user'] = $oSubscriber->getID();			$aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.			$aNotificationOptions['target_name'] = $oRemovedFolder->getName();			$aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId());			$aNotificationOptions['object_id'] = $oParentFolder->getId();  // parent folder_id, since the removed one is removed.			$aNotificationOptions['event_type'] = "RemoveSubscribedFolder";			$oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);			// now the email content.			// FIXME this needs to be handled entirely within notifications from now on.			if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {			    $emailContent = $content->getEmailAlertContent($oNotification);			    $emailSubject = $content->getEmailAlertSubject($oNotification);			    $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);			    $oEmail->send();			}			// now grab each oSubscribers oSubscription, and delete.			$oSubscription = Subscription::getByIds($oSubscriber->getId(), $oRemovedFolder->getId(), $this->subscriptionTypes["Folder"]);			if (!(PEAR::isError($oSubscription) || ($oSubscription == false))) {			    $oSubscription->delete();			}		}		// now handle (for those who haven't been alerted) users watching the folder.		$aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $parentId = $oParentFolder->getId();		$this->sendNotification($aUsers, 'RemoveChildFolder', $oRemovedFolder->getName(), $oParentFolder->getId(), $parentId);	}    function RemoveDocument($oRemovedDocument, $oParentFolder) {        $content = new SubscriptionContent(); // needed for i18n	    // two cases to consider here:		//    - notify people who are subscribed to the parent folder.		//    - notify and unsubscribe people who are subscribed to the actual folder.		// we need to start with the latter, so we don't "lose" any.		$aUsers = $this->_getSubscribers($oRemovedDocument->getId(), $this->subscriptionTypes["Document"]);		foreach ($aUsers as $oSubscriber) {		    // notification object first.			$aNotificationOptions = array();			$aNotificationOptions['target_user'] = $oSubscriber->getID();		    $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.		    $aNotificationOptions['target_name'] = $oRemovedDocument->getName();		    $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId());		    $aNotificationOptions['object_id'] = $oParentFolder->getId();  // parent folder_id, since the removed one is removed.		    $aNotificationOptions['event_type'] = "RemoveSubscribedDocument";			$oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);			// now the email content.			// FIXME this needs to be handled entirely within notifications from now on.			if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {			    $emailContent = $content->getEmailAlertContent($oNotification);				$emailSubject = $content->getEmailAlertSubject($oNotification);				$oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);				$oEmail->send();			}			// now grab each oSubscribers oSubscription, and delete.			$oSubscription = Subscription::getByIds($oSubscriber->getId(), $oRemovedDocument->getId(), $this->subscriptionTypes["Document"]);			if (!(PEAR::isError($oSubscription) || ($oSubscription == false))) {			    $oSubscription->delete();			}		}		// now handle (for those who haven't been alerted) users watching the folder.		$aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $parentId = $oParentFolder->getId();		$this->sendNotification($aUsers, 'RemoveChildDocument', $oRemovedDocument->getName(), $oParentFolder->getId(), $parentId);	}    function ModifyDocument($oModifiedDocument, $oParentFolder)  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFolderUsers);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'ModifyDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId);    }    function DiscussDocument($oModifiedDocument, $oParentFolder)  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFolderUsers);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'DiscussDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId);    }    function CheckInDocument($oModifiedDocument, $oParentFolder)  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFolderUsers);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'CheckInDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId);    }    function CheckOutDocument($oModifiedDocument, $oParentFolder)  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFolderUsers);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'CheckOutDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId);    }    function MoveDocument($oMovedDocument, $oToFolder, $oFromFolder, $moveOrCopy = "MovedDocument")  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oMovedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFromUsers = $this->_getSubscribers($oFromFolder->getId(), $this->subscriptionTypes["Folder"]);        $aFolderUsers = $this->_getSubscribers($oToFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFromUsers);        $aUsers = array_merge($aUsers, $aFolderUsers);        $parentId = $oToFolder->getId();        $this->sendNotification($aUsers, $moveOrCopy, $oMovedDocument->getName(), $oToFolder->getId(), $parentId);    }    function ArchivedDocument($oModifiedDocument, $oParentFolder)  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFolderUsers);        $parentId = $oParentFolder->getId();        $this->sendNotification($aUsers, 'ArchivedDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId);    }    function RestoreDocument($oModifiedDocument, $oParentFolder)  {        $content = new SubscriptionContent(); // needed for i18n	    // OK:  two actions:  document registrants, folder registrants.        $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]);        $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);        $aUsers = array_merge($aDocUsers, $aFolderUsers);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -