ktsubscriptions.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 625 行 · 第 1/2 页
SVN-BASE
625 行
<?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): ______________________________________ * */require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc');require_once(KT_LIB_DIR . '/subscriptions/SubscriptionManager.inc');require_once(KT_LIB_DIR . "/subscriptions/subscriptions.inc.php");require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');require_once(KT_LIB_DIR . '/widgets/portlet.inc.php');require_once(KT_LIB_DIR . '/actions/documentaction.inc.php');require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');class KTSubscriptionPlugin extends KTPlugin { var $sNamespace = "ktstandard.subscriptions.plugin"; var $autoRegister = true; function KTSubscriptionPlugin($sFilename = null) { $res = parent::KTPlugin($sFilename); $this->sFriendlyName = _kt('Subscription Plugin'); return $res; } function setup() { $this->registerPortlet('browse', 'KTSubscriptionPortlet', 'ktcore.portlets.subscription', __FILE__); $this->registerAction('documentsubscriptionaction', 'KTDocumentSubscriptionAction', 'ktstandard.subscription.documentsubscription'); $this->registerAction('documentsubscriptionaction', 'KTDocumentUnsubscriptionAction', 'ktstandard.subscription.documentunsubscription'); $this->registerTrigger('checkout', 'postValidate', 'KTCheckoutSubscriptionTrigger', 'ktstandard.triggers.subscription.checkout'); $this->registerTrigger('edit', 'postValidate', 'KTEditSubscriptionTrigger', 'ktstandard.triggers.subscription.checkout'); $this->registerTrigger('delete', 'postValidate', 'KTDeleteSubscriptionTrigger', 'ktstandard.triggers.subscription.delete'); $this->registerTrigger('moveDocument', 'postValidate', 'KTDocumentMoveSubscriptionTrigger', 'ktstandard.triggers.subscription.moveDocument'); $this->registerTrigger('archive', 'postValidate', 'KTArchiveSubscriptionTrigger', 'ktstandard.triggers.subscription.archive'); $this->registerTrigger('discussion', 'postValidate', 'KTDiscussionSubscriptionTrigger', 'ktstandard.triggers.subscription.archive'); $this->registerAction('foldersubscriptionaction', 'KTFolderSubscriptionAction', 'ktstandard.subscription.foldersubscription'); $this->registerAction('foldersubscriptionaction', 'KTFolderUnsubscriptionAction', 'ktstandard.subscription.folderunsubscription'); $this->registerPage('manage', 'KTSubscriptionManagePage'); }}$oRegistry =& KTPluginRegistry::getSingleton();$oRegistry->registerPlugin('KTSubscriptionPlugin', 'ktstandard.subscriptions.plugin', __FILE__);function wrapString($str, $length = 20){ // Wrap string to given character length (content rendered from ajax doesn't render correctly in ie) $len = mb_strlen($str); $out = ''; $pos = 0; while($len > $length && $pos !== false){ $pos = mb_strpos($str, ' ', $length); $line = mb_strcut($str, 0, $pos+1); $str = mb_strcut($str, $pos+1); $len = mb_strlen($str); $out .= $line.'<br>'; } $out .= $str; return $out;}// {{{ KTSubscriptionPortletclass KTSubscriptionPortlet extends KTPortlet { function KTSubscriptionPortlet() { parent::KTPortlet(_kt("Subscriptions")); } function render() { if ($this->oDispatcher->oUser->isAnonymous()) { return null; } if($this->oDispatcher->oDocument){ $oObject = $this->oDispatcher->oDocument; $type = 'documentsubscriptionaction'; }else if($this->oDispatcher->oFolder){ $oObject = $this->oDispatcher->oFolder; $type = 'foldersubscriptionaction'; }else{ // not in a folder or document return null; } global $default; $serverName = $default->serverName; $base_url = ($default->sslEnabled ? 'https' : 'http') .'://'.$serverName; $oUser = $this->oDispatcher->oUser; $this->actions = array(); // Get the actions $oKTActionRegistry =& KTActionRegistry::getSingleton(); $actions = $oKTActionRegistry->getActions($type); foreach ($actions as $aAction){ list($sClassName, $sPath) = $aAction; $oSubscription = new $sClassName($oObject, $oUser); $actionInfo = $oSubscription->getInfo(); if(!empty($actionInfo)){ if(isset($actionInfo['active']) && $actionInfo['active'] == 'no'){ $nonActiveUrl = $base_url.$actionInfo['url']; $nonActiveName = $actionInfo['name']; }else { $aInfo = $actionInfo; } } } // Create js script $url = $base_url.$aInfo['url']; $script = '<script type="text/javascript"> function doSubscribe(action){ var respDiv = document.getElementById("response"); var link = document.getElementById("subscribeLink"); Ext.Ajax.request({ url: "'.$url.'", success: function(response) { respDiv.innerHTML = response.responseText; respDiv.style.display = "block"; link.style.display = "none"; if(document.getElementById("subLink")){ document.getElementById("subLink").style.display = "none"; } }, failure: function() { respDiv.innerHTML = "'._kt('There was a problem with the subscription, please refresh the page and try again.').'"; respDiv.style.display = "block"; }, params: { action: action } }); } </script>'; $script .= "<a id='subscribeLink' style='cursor:pointer' onclick='javascript: doSubscribe(\"ajax\")'>{$aInfo['name']}</a>"; $aInfo['js'] = $script; $this->actions[] = $aInfo; if(isset($aInfo['subaction'])){ $subInfo = array(); $subInfo['js'] = "<a id='subLink' style='cursor:pointer' onclick='javascript: doSubscribe(\"add_subfolders\")'>{$aInfo['subaction']}</a>"; $this->actions[] = $subInfo; } $this->actions[] = array("name" => _kt("Manage subscriptions"), "url" => $this->oPlugin->getPagePath('manage')); $btn = '<div id="response" style="padding: 2px; margin-right: 10px; margin-left: 10px; background: #CCC; display:none;"></div>'; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/portlets/actions_portlet"); $aTemplateData = array( 'context' => $this, 'btn' => $btn ); return $oTemplate->render($aTemplateData); }}// }}}// {{{ KTDocumentSubscriptionActionclass KTDocumentSubscriptionAction extends KTDocumentAction { var $sName = 'ktstandard.subscription.documentsubscription'; function getDisplayName() { return _kt('Subscribe to document'); } function getInfo() { $aInfo = parent::getInfo(); if (Subscription::exists($this->oUser->getID(), $this->oDocument->getID(), SubscriptionEvent::subTypes('Document'))) { $aInfo['active'] = 'no'; } return $aInfo; } function do_ajax() { $iSubscriptionType = SubscriptionEvent::subTypes('Document'); if (Subscription::exists($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType)) { $str = _kt('You are already subscribed to that document'); } else { $oSubscription = new Subscription($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType); $res = $oSubscription->create(); if ($res) { $str = _kt('You have been subscribed to this document'); } else { $str = _kt('There was a problem subscribing you to this document'); } } $str = wrapString($str); echo $str; exit(0); } function do_main() { $iSubscriptionType = SubscriptionEvent::subTypes('Document'); if (Subscription::exists($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType)) { $_SESSION['KTErrorMessage'][] = _kt("You are already subscribed to that document"); } else { $oSubscription = new Subscription($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType); $res = $oSubscription->create(); if ($res) { $_SESSION['KTInfoMessage'][] = _kt("You have been subscribed to this document"); } else { $_SESSION['KTErrorMessage'][] = _kt("There was a problem subscribing you to this document"); } } controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); }}// }}}// {{{ KTDocumentUnsubscriptionActionclass KTDocumentUnsubscriptionAction extends KTDocumentAction { var $sName = 'ktstandard.subscription.documentunsubscription'; function getDisplayName() { return _kt('Unsubscribe from document'); } function getInfo() { $aInfo = parent::getInfo(); if (!Subscription::exists($this->oUser->getID(), $this->oDocument->getID(), SubscriptionEvent::subTypes('Document'))) { $aInfo['active'] = 'no'; } return $aInfo; } function do_ajax() { $iSubscriptionType = SubscriptionEvent::subTypes('Document'); if (!Subscription::exists($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType)) { $str = _kt('You are not subscribed to this document'); } else { $oSubscription = new Subscription($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType); $res = $oSubscription->create(); if ($res) { $str = _kt('You have been unsubscribed from this document'); } else { $str = _kt('There was a problem unsubscribing you from this document'); } } $str = wrapString($str); echo $str; exit(0); } function do_main() { $iSubscriptionType = SubscriptionEvent::subTypes('Document'); if (!Subscription::exists($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType)) { $_SESSION['KTErrorMessage'][] = _kt("You were not subscribed to that document"); } else { $oSubscription = & Subscription::getByIDs($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType); $res = $oSubscription->delete(); if ($res) { $_SESSION['KTInfoMessage'][] = _kt("You have been unsubscribed from this document"); } else { $_SESSION['KTErrorMessage'][] = _kt("There was a problem unsubscribing you from this document"); } } controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); }}// }}}// {{{ KTCheckoutSubscriptionTriggerclass KTCheckoutSubscriptionTrigger {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?