ktbulkactions.php.tmp

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 1,219 行 · 第 1/3 页

TMP
1,219
字号
        $oForm->setValidators(array(            array('ktcore.validators.string', array(                'test' => 'reason',                'output' => 'reason',            )),        ));        return $oForm;    }    function check_entity($oEntity) {        if(is_a($oEntity, 'Document')) {            if(!KTDocumentUtil::canBeMoved($oEntity)) {                return PEAR::raiseError(_kt('Document cannot be copied'));            }        }        return parent::check_entity($oEntity);    }    // info collection step    function do_collectinfo() {        $this->store_lists();        $this->get_lists();	$oTemplating =& KTTemplating::getSingleton();	$oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info');        return $oTemplate->render(array('context' => $this,                                        'form' => $this->form_collectinfo()));    }    function do_performaction() {        $this->store_lists();        $this->get_lists();        $oForm = $this->form_collectinfo();        $res = $oForm->validate();        if (!empty($res['errors'])) {            $oForm->handleError();        }        $this->sReason = $_REQUEST['data']['reason'];        $this->iTargetFolderId = $_REQUEST['data']['fFolderId'];        $this->oTargetFolder = Folder::get($this->iTargetFolderId);        $_REQUEST['fReturnData'] = '';        $_REQUEST['fFolderId'] = $this->iTargetFolderId;        // does it exists        if(PEAR::isError($this->oTargetFolder)) {            return PEAR::raiseError(_kt('Invalid target folder selected'));        }        // does the user have write permission        if(!Permission::userHasFolderWritePermission($this->oTargetFolder)) {            $this->errorRedirectTo('collectinfo', _kt('You do not have permission to move items to this location'));        }        return parent::do_performaction();    }    function perform_action($oEntity) {        if(is_a($oEntity, 'Document')) {            return KTDocumentUtil::copy($oEntity, $this->oTargetFolder, $this->sReason);        } else if(is_a($oEntity, 'Folder')) {            return KTFolderUtil::copy($oEntity, $this->oTargetFolder, $this->oUser, $this->sReason);        }    }}class KTBulkArchiveAction extends KTBulkAction {    var $sName = 'ktcore.actions.bulk.archive';    var $_sPermission = 'ktcore.permissions.write';    var $_bMutator = true;    function getDisplayName() {        return _kt('Archive');    }    function form_collectinfo() {        $oForm = new KTForm;        $oForm->setOptions(array(            'identifier' => 'ktcore.actions.bulk.archive.form',            'label' => _kt('Archive Items'),            'submit_label' => _kt('Archive'),            'action' => 'performaction',            'fail_action' => 'collectinfo',            'cancel_action' => 'main',            'context' => $this,        ));        $oForm->addWidget(            array('ktcore.widgets.reason',array(                'name' => 'reason',                'label' => _kt('Reason'),                'description' => _kt('The reason for archiving these documents and folders, for historical purposes.'),                'value' => null,                'required' => true,                )        ));        $oForm->setValidators(array(            array('ktcore.validators.string', array(                'test' => 'reason',                'output' => 'reason',            )),        ));        return $oForm;    }    function check_entity($oEntity) {        if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) {                return PEAR::raiseError(_kt('Document cannot be archived'));        }        if($oEntity->isSymbolicLink()){        	return PEAR::raiseError(_kt("It is not possible to archive a shortcut. Please archive the target document or folder instead."));        }        return parent::check_entity($oEntity);    }	/**     * build the confirmation form that is shown when symlinks are affected by this action.     *     * @return KTForm the form     */	function form_confirm() {        $oForm = new KTForm;        $oForm->setOptions(array(            'label' => _kt('Are you sure?'),            'description' => _kt('There are shortcuts linking to some of the documents or folders in your selection; continuing will automatically delete the shortcuts. Would you like to continue?'),            'action' => 'collectinfo',            'fail_action' => 'main',            'cancel_url' => KTBrowseUtil::getUrlForFolder($this->oFolder),            'submit_label' => _kt('Continue'),            'context' => $this,        ));        $oForm->setWidgets(array(        array('ktcore.widgets.hidden',array(        	'name' => 'archive_confirmed',        	'value' => '1'        ))));        return $oForm;    }    /**     * Shows the confirmation form if symlinks are affected by the current action     *     * @return Template HTML     */	function do_confirm(){		$this->store_lists();        $this->get_lists();    	$this->oPage->setBreadcrumbDetails(_kt('Confirm archive'));    	$oTemplate =& $this->oValidator->validateTemplate('ktcore/bulk_action_confirm');        $oForm = $this->form_confirm();    	$oTemplate->setData(array(            'context' => &$this,            'form' => $oForm,        ));        return $oTemplate->render();    }    // info collection step    function do_collectinfo() {        $this->store_lists();        $this->get_lists();        //check if a the symlinks deletion confirmation has been passed yet		if(KTutil::arrayGet($_REQUEST['data'],'archive_confirmed') != 1){			//check if there are actually any symlinks involved.        	if($this->symlinksLinkingToCurrentList()){        		$this->redirectTo("confirm");        	}        }		$oTemplating =& KTTemplating::getSingleton();		$oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info');        return $oTemplate->render(array('context' => $this,                                        'form' => $this->form_collectinfo()));    }    function do_performaction() {        $this->store_lists();        $this->get_lists();        $oForm = $this->form_collectinfo();        $res = $oForm->validate();        if (!empty($res['errors'])) {            $oForm->handleError();        }        $this->sReason = $_REQUEST['data']['reason'];        return parent::do_performaction();    }    function perform_action($oEntity) {        if(is_a($oEntity, 'Document')) {            $res = KTDocumentUtil::archive($oEntity, $this->sReason);            if(PEAR::isError($res)){                return $res;            }            return true;        }else if(is_a($oEntity, 'Folder')) {            $aDocuments = array();            $aChildFolders = array();            $oFolder = $oEntity;            // Get folder id            $sFolderId = $oFolder->getID();            // Get documents in folder            $sDocuments = $oFolder->getDocumentIDs($sFolderId);            $aDocuments = explode(',', $sDocuments);            // Get all the folders within the folder            $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR            parent_folder_ids LIKE '{$sFolderId},%' OR            parent_folder_ids LIKE '%,{$sFolderId},%' OR            parent_folder_ids LIKE '%,{$sFolderId}'";            $aChildFolders = $this->oFolder->getList($sWhereClause);            // Loop through folders and get documents            if(!empty($aChildFolders)){                foreach($aChildFolders as $oChild){                    $sChildId = $oChild->getID();                    $sChildDocs = $oChild->getDocumentIDs($sChildId);                    if (PEAR::isError($res)) {                       return false;                    }                    if(!empty($sChildDocs)){                        $aChildDocs = explode(',', $sChildDocs);                        $aDocuments = array_merge($aDocuments, $aChildDocs);                    }                }            }            // Archive all documents            if(!empty($aDocuments)){                foreach($aDocuments as $sDocumentId){                    $oDocument = Document::get($sDocumentId);                    if(PEAR::isError($oDocument)){                        return $oDocument;                    }                    $res = KTDocumentUtil::archive($oDocument, $this->sReason);                    if(PEAR::isError($res)){                        return $res;                    }                }            }            return true;        }    }}class KTBrowseBulkExportAction extends KTBulkAction {    var $sName = 'ktcore.actions.bulk.export';    var $_sPermission = 'ktcore.permissions.read';    var $_bMutator = true;    var $bNotifications = true;    function getDisplayName() {        return _kt('Download All');    }    function check_entity($oEntity) {        if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) {                return PEAR::raiseError(_kt('Document cannot be exported'));        }        //we need to do an extra folder permission check in case of a shortcut        if(is_a($oEntity,'Folder') && $oEntity->isSymbolicLink()){	    	if(!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $this->_sPermission, $oEntity->getLinkedFolder())) {	            return PEAR::raiseError(_kt('You do not have the required permissions'));	        }        }        return parent::check_entity($oEntity);    }    function do_performaction() {        $folderName = $this->oFolder->getName();        $this->oZip = new ZipFolder($folderName);        $res = $this->oZip->checkConvertEncoding();        $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder);        $sReturn = sprintf('<p>' . _kt('Return to the original <a href="%s">folder</a>') . "</p>\n", $folderurl);        if(PEAR::isError($res)){            $this->addErrorMessage($res->getMessage());            return $sReturn;        }        $this->startTransaction();        $oKTConfig =& KTConfig::getSingleton();        $this->bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations");        $this->bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false;        $result = parent::do_performaction();        $sExportCode = $this->oZip->createZipFile();        if(PEAR::isError($sExportCode)){            $this->addErrorMessage($sExportCode->getMessage());            return $sReturn;        }        $oTransaction = KTFolderTransaction::createFromArray(array(            'folderid' => $this->oFolder->getId(),            'comment' => "Bulk export",            'transactionNS' => 'ktstandard.transactions.bulk_export',            'userid' => $_SESSION['userID'],            'ip' => Session::getClientIP(),        ));        $this->commitTransaction();        $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $this->oFolder->getId(), $sExportCode));        $str = sprintf('<p>' . _kt('Your download will begin shortly. If you are not automatically redirected to your download, please click <a href="%s">here</a> ') . "</p>\n", $url);        $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder);        $str .= sprintf('<p>' . _kt('Once your download is complete, click <a href="%s">here</a> to return to the original folder') . "</p>\n", $folderurl);        //$str .= sprintf("</div></div></body></html>\n");        $str .= sprintf('<script language="JavaScript">                function kt_bulkexport_redirect() {                document.location.href = "%s";                }                callLater(1, kt_bulkexport_redirect);                </script>', $url);        return $str;    }    function perform_action($oEntity) {        if(is_a($oEntity, 'Document')) {			$oDocument = $oEntity;	        if($oDocument->isSymbolicLink()){	    		$oDocument->switchToLinkedCore();	    	}            if ($this->bNoisy) {                $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());                $oDocumentTransaction->create();            }            // fire subscription alerts for the downloaded document - if global config is set            if($this->bNotifications){                $oSubscriptionEvent = new SubscriptionEvent();                $oFolder = Folder::get($oDocument->getFolderID());                $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);            }            $this->oZip->addDocumentToZip($oDocument);        }else if(is_a($oEntity, 'Folder')) {            $aDocuments = array();            $oFolder = $oEntity;            if($oFolder->isSymbolicLink()){            	$oFolder = $oFolder->getLinkedFolder();            }            $sFolderId = $oFolder->getId();            $sFolderDocs = $oFolder->getDocumentIDs($sFolderId);            // Add folder to zip            $this->oZip->addFolderToZip($oFolder);            if(!empty($sFolderDocs)){                $aDocuments = explode(',', $sFolderDocs);            }            // Get all the folders within the current folder            $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR            parent_folder_ids LIKE '{$sFolderId},%' OR            parent_folder_ids LIKE '%,{$sFolderId},%' OR            parent_folder_ids LIKE '%,{$sFolderId}'";            $aFolderList = $this->oFolder->getList($sWhereClause);			$aLinkingFolders = $this->getLinkingEntities($aFolderList);            $aFolderList = array_merge($aFolderList,$aLinkingFolders);            $aFolderObjects = array();            $aFolderObjects[$sFolderId] = $oFolder;            // Export the folder structure to ensure the export of empty directories            if(!empty($aFolderList)){                foreach($aFolderList as $k => $oFolderItem){                	if(Permission::userHasFolderReadPermission($oFolderItem)){	                    // Get documents for each folder	                    if($oFolderItem->isSymbolicLink()){	                    	$oFolderItem = $oFolderItem->getLinkedFolder();	                    }	                    $sFolderItemId = $oFolderItem->getID();	                    $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);	                    if(!empty($sFolderItemDocs)){

⌨️ 快捷键说明

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