ktdocumentlinks.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 595 行 · 第 1/2 页
SVN-BASE
595 行
{ if($iTempParentDocId == $iTempDocId) { $this->errorRedirectToMain(_kt('A document cannot be linked to itself.')); } } } $this->oPage->setBreadcrumbDetails(_kt("link")); $sType = (isset($_REQUEST['linktype'])) ? $_REQUEST['linktype'] : 'internal'; $sTarget = ''; $aTarget = array(); if($sType == 'external'){ $iParentId = $_REQUEST['fDocumentId']; $aTarget['url'] = $_REQUEST['target_url']; $aTarget['name'] = $_REQUEST['target_name']; $aDocuments = array($iParentId); $this->oValidator->validateUrl($aTarget['url']); if(empty($aTarget['name'])){ $aTarget['name'] = $aTarget['url']; } }else{ $iParentId = $_REQUEST['fDocumentId']; $aDocuments = $_REQUEST['linkselection']; if(empty($aDocuments)){ $this->errorRedirectToMain(_kt('No documents have been selected.')); exit; } } $sDocuments = serialize($aDocuments); $sTarget = serialize($aTarget); // form fields $aFields = array(); $aVocab = array(); $aLinkTypes = LinkType::getList("id > 0"); foreach($aLinkTypes as $oLinkType) { $aVocab[$oLinkType->getID()] = $oLinkType->getName(); } $aOptions = array('vocab' => $aVocab); $aFields[] = new KTLookupWidget( _kt('Link Type'), _kt('The type of link you wish to use'), 'fLinkTypeId', null, $this->oPage, true, null, null, $aOptions); $aTemplateData = array( 'context' => $this, 'parent_id' => $iParentId, 'target_id' => $sDocuments, 'target_url' => $sTarget, 'fields' => $aFields, ); $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/link_type_select'); return $oTemplate->render($aTemplateData); } // make the link function do_make_link() { $this->oPage->setBreadcrumbDetails(_kt("link")); $iParentId = $_REQUEST['fDocumentId']; $iLinkTypeId = $_REQUEST['fLinkTypeId']; $sDocIds = $_REQUEST['fTargetDocumentId']; $aDocIds = unserialize($sDocIds); $sTarget = $_REQUEST['fTargetUrl']; $aTarget = unserialize($sTarget); $oLinkType = LinkType::get($iLinkTypeId); if (PEAR::isError($oLinkType)) { $this->errorRedirectToMain(_kt('Invalid link type selected.')); exit(0); } $sTargetUrl = ''; $sTargetName = ''; if(!empty($aTarget)){ $sTargetUrl = $aTarget['url']; $sTargetName = $aTarget['name']; } // create document links $this->startTransaction(); if(!empty($aDocIds)){ foreach ($aDocIds as $iDocId){ $oDocumentLink =& DocumentLink::createFromArray(array( 'iParentDocumentId' => $iParentId, 'iChildDocumentId' => $iDocId, 'iLinkTypeId' => $iLinkTypeId, 'sTargetUrl' => $sTargetUrl, 'sTargetName' => $sTargetName, )); if (PEAR::isError($oDocumentLink)) { $this->rollbackTransaction(); $this->errorRedirectToMain(_kt('Could not create document link'), sprintf('fDocumentId=%d', $iParentId)); exit(0); } } } $this->commitTransaction(); $this->successRedirectToMain(_kt('Document link created'), sprintf('fDocumentId=%d', $iParentId)); exit(0); } // delete a link function do_delete() { $this->oPage->setBreadcrumbDetails(_kt("link")); // check security $oPermission =& KTPermission::getByName('ktcore.permissions.write'); if (PEAR::isError($oPermission) || !KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument)) { $this->errorRedirectToMain(_kt('You do not have sufficient permissions to delete a link'), sprintf("fDocumentId=%d", $this->oDocument->getId())); exit(0); } // check validity of things $oDocumentLink = DocumentLink::get(KTUtil::arrayGet($_REQUEST, 'fDocumentLinkId')); if (PEAR::isError($oDocumentLink)) { $this->errorRedirectToMain(_kt('Invalid document link selected.')); exit(0); } $oParentDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fDocumentId')); if (PEAR::isError($oParentDocument)) { $this->errorRedirectToMain(_kt('Invalid document selected.')); exit(0); } // do deletion $this->startTransaction(); $res = $oDocumentLink->delete(); if (PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Could not delete document link'), sprintf('fDocumentId=%d', $oParentDocument->getId())); exit(0); } $this->commitTransaction(); $this->successRedirectToMain(_kt('Document link deleted'), sprintf('fDocumentId=%d', $oParentDocument->getId())); exit(0); }}class KTDocLinkAdminDispatcher extends KTAdminDispatcher { var $sHelpPage = 'ktcore/admin/link type management.html'; // Breadcrumbs base - added to in methods function check() { return true; } function do_main() { $this->aBreadcrumbs[] = array('name' => _kt('Document Links')); $this->oPage->setBreadcrumbDetails(_kt("view")); $aLinkTypes =& LinkType::getList('id > 0'); $addLinkForm = array(); // KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) $addLinkForm[] = new KTStringWidget(_kt('Name'), _kt('A short, human-readable name for the link type.'), 'fName', null, $this->oPage, true); $addLinkForm[] = new KTStringWidget(_kt('Description'), _kt('A short brief description of the relationship implied by this link type.'), 'fDescription', null, $this->oPage, true); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/linktypesadmin'); $oTemplate->setData(array( "context" => $this, "add_form" => $addLinkForm, "links" => $aLinkTypes, )); return $oTemplate; } function do_edit() { $link_id = KTUtil::arrayGet($_REQUEST, 'fLinkTypeId', null, false); if ($link_id === null) { $this->errorRedirectToMain(_kt("Please specify a link type to edit.")); } $oLinkType =& LinkType::get($link_id); $this->aBreadcrumbs[] = array('name' => _kt('Document Links')); $this->oPage->setBreadcrumbDetails(_kt("view")); $aLinkTypes =& LinkType::getList('id > 0'); $editLinkForm = array(); // KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) $editLinkForm[] = new KTStringWidget(_kt('Name'), _kt('A short, human-readable name for the link type.'), 'fName', $oLinkType->getName(), $this->oPage, true); $editLinkForm[] = new KTStringWidget(_kt('Description'), _kt('A short brief description of the relationship implied by this link type.'), 'fDescription', $oLinkType->getDescription(), $this->oPage, true); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/linktypesadmin'); $oTemplate->setData(array( "context" => $this, "edit_form" => $editLinkForm, "old_link" => $oLinkType, "links" => $aLinkTypes, )); return $oTemplate; } function do_update() { $link_id = KTUtil::arrayGet($_REQUEST, 'fLinkTypeId', null, false); if ($link_id === null) { $this->errorRedirectToMain(_kt("Please specify a link type to update.")); } $name = KTUtil::arrayGet($_REQUEST, 'fName'); $description = KTUtil::arrayGet($_REQUEST, 'fDescription'); if (empty($name) || empty($description)) { // for bonus points, make this go to edit, and edit catch it. $this->errorRedirectToMain(_kt('Please enter information for all fields.')); } $oLinkType =& LinkType::get($link_id); $oLinkType->setName($name); $oLinkType->setDescription($description); $oLinkType->update(); $this->successRedirectToMain(_kt("Link Type updated.")); } function do_add() { $name = KTUtil::arrayGet($_REQUEST, 'fName'); $description = KTUtil::arrayGet($_REQUEST, 'fDescription'); if (empty($name) || empty($description)) { $this->errorRedirectToMain(_kt('Please enter information for all fields.')); } $oLinkType = new LinkType($name, $description); $oLinkType->create(); //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); $this->successRedirectToMain(_kt("Link Type created.")); } function do_delete() { $types_to_delete = KTUtil::arrayGet($_REQUEST, 'fLinksToDelete'); // is an array. if (empty($types_to_delete)) { $this->errorRedirectToMain(_kt('Please select one or more link types to delete.')); } $count = 0; foreach ($types_to_delete as $link_id) { $oLinkType = LinkType::get($link_id); $aLinks = DocumentLink::getList(sprintf("link_type_id = %d", $link_id)); if(!empty($aLinks)){ foreach($aLinks as $oLink) { $oLink->delete(); } } $oLinkType->delete(); // technically, this is a bad thing $count += 1; } //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); $this->successRedirectToMain($count . " " . _kt("Link types deleted.")); }}$oRegistry =& KTPluginRegistry::getSingleton();$oRegistry->registerPlugin('KTDocumentLinks', 'ktstandard.documentlinks.plugin', __FILE__);?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?