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

📄 ondiskpathstoragemanager.inc.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
        $aParams = array(
            $sDestFolderPath,
            strlen($oFolder->getFullPath()) + 1,
            sprintf("%s%%", $sSrcFolderPath),
        );
        $res = DBUtil::runQuery(array($sQuery, $aParams));
        if (PEAR::isError($res)) {
            return $res;
        }

        $oConfig =& KTConfig::getSingleton();
        $sSrc = sprintf("%s/%s",
            $oConfig->get('urls/documentRoot'),
            $sSrcFolderPath
        );
        $sDst = sprintf("%s/%s/%s",
            $oConfig->get('urls/documentRoot'),
            $sDestFolderPath,
            $oFolder->getName()
        );
        return KTUtil::moveDirectory($sSrc, $sDst);
    }

    function renameFolder($oFolder, $sNewName) {
        $table = "document_content_version";
        $sQuery = "UPDATE $table SET storage_path = CONCAT(?, SUBSTRING(storage_path FROM ?)) WHERE storage_path LIKE ?";

        if ($oFolder->getId() == 1) {
            $sSrcFolderPath = $oFolder->getName();
            $sDestFolderPath = $sNewName;
        } else {
            $sSrcFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName());
            $sDestFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $sNewName);
        }

        $aParams = array(
            $sDestFolderPath,
            strlen($sSrcFolderPath) + 1,
            sprintf("%s%%", $sSrcFolderPath),
        );
        $res = DBUtil::runQuery(array($sQuery, $aParams));
        if (PEAR::isError($res)) {
            return $res;
        }

        $oConfig =& KTConfig::getSingleton();
        $sSrc = sprintf("%s/%s",
            $oConfig->get('urls/documentRoot'),
            $sSrcFolderPath
        );
        $sDst = sprintf("%s/%s",
            $oConfig->get('urls/documentRoot'),
            $sDestFolderPath
        );
        $res = @rename($sSrc, $sDst);
		if (PEAR::isError($res) || ($res == false)) {
		    print '<br /> -- unable to move ' . $sSrc . ' to ' . $sDst . '    ';
		    return false;
		    // return PEAR::raiseError('unable to move directory to ' . $sDst);
		}

		return true;
    }

	/**
     * Perform any storage changes necessary to account for a copied
     * document object.
     */
     function copy($oSrcDocument, &$oNewDocument) {
        // we get the Folder object
		$oVersion = $oNewDocument->_oDocumentContentVersion;
		$oConfig =& KTConfig::getSingleton();
		$sDocumentRoot = $oConfig->get('urls/documentRoot');

		$sNewPath = $this->generateStoragePath($oNewDocument);
		$sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $this->generateStoragePath($oSrcDocument));
		$sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);

		$res = KTUtil::copyFile($sFullOldPath, $sFullNewPath);
		if (PEAR::isError($res)) { return $res; }
		$oVersion->setStoragePath($sNewPath);
		$oVersion->update();
     }

	 /**
     * Perform any storage changes necessary to account for a renamed
     * document object.
	 * someone else _must_ call the update on $oDocument
     */
     function renameDocument(&$oDocument, $oOldContentVersion, $sNewFilename) {
        // we get the Folder object
		$oVersion =& $oDocument->_oDocumentContentVersion;
		$oConfig =& KTConfig::getSingleton();
		$sDocumentRoot = $oConfig->get('urls/documentRoot');

		$sOldPath = sprintf("%s/%s-%s", Folder::generateFolderPath($oDocument->getFolderID()), $oOldContentVersion->getId(), $oOldContentVersion->getFileName());
		$sNewPath = sprintf("%s/%s-%s", Folder::generateFolderPath($oDocument->getFolderID()), $oDocument->_oDocumentContentVersion->getId(), $sNewFilename);
		$sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath);
		$sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);

		$res = KTUtil::copyFile($sFullOldPath, $sFullNewPath);
		if (PEAR::isError($res)) { return $res; }

		$oVersion->setStoragePath($sNewPath);
		// someone else _must_ call the update.
		return true;		 // RES ?= PEAR::raiseError('.');
     }

	/**
	 * Deletes a document- moves it to the Deleted/ folder
	 *
	 * return boolean true on successful move, false otherwhise
	 */
	function delete($oDocument) {
        $oConfig =& KTConfig::getSingleton();
		$sCurrentPath = $this->getPath($oDocument);

		// check if the deleted folder exists and create it if not
        $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
		if (!file_exists($sDeletedPrefix)) {
            mkdir($sDeletedPrefix, 0755);
        }

        $sDocumentRoot = $oConfig->get('urls/documentRoot');

        $aVersions = KTDocumentContentVersion::getByDocument($oDocument);
        foreach ($aVersions as $oVersion) {
            $sOldPath = $oVersion->getStoragePath();
            $sNewPath = sprintf("Deleted/%s-%s", $oVersion->getId(), $oVersion->getFileName());
            $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath);
            $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);
            KTUtil::moveFile($sFullOldPath, $sFullNewPath);
        }
        return true;
	}

	/**
	 * Completely remove a document from the Deleted/ folder
	 *
	 * return boolean true on successful expunge
	 */
	function expunge($oDocument) {
		parent::expunge($oDocument);
        $oConfig =& KTConfig::getSingleton();
		$sCurrentPath = $this->getPath($oDocument);

		// check if the deleted folder exists and create it if not
        $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
        $sDocumentRoot = $oConfig->get('urls/documentRoot');

        $aVersions = KTDocumentContentVersion::getByDocument($oDocument);
        foreach ($aVersions as $oVersion) {
            $sPath = sprintf("Deleted/%s-%s", $oVersion->getId(), $oVersion->getFileName());
            $sFullPath = sprintf("%s/%s", $sDocumentRoot, $sPath);
            if (file_exists($sFullPath)) {
                unlink($sFullPath);
            }
        }
        return true;
	}

	/**
	 * Completely remove a document version
	 *
	 * return boolean true on successful delete
	 */
	function deleteVersion($oVersion) {
	    $oConfig =& KTConfig::getSingleton();
	    $sDocumentRoot = $oConfig->get('urls/documentRoot');
	    $iContentId = $oVersion->getContentVersionId();
        $oContentVersion = KTDocumentContentVersion::get($iContentId);

	    $sPath = $oContentVersion->getStoragePath();
	    $sFullPath = sprintf("%s/%s", $sDocumentRoot, $sPath);
	    if (file_exists($sFullPath)) {
            unlink($sFullPath);
	    }
	    return true;
	}

	/**
	 * Restore a document from the Deleted/ folder to the specified folder
	 *
	 * return boolean true on successful move, false otherwhise
	 */
	function restore($oDocument) {
        $oConfig =& KTConfig::getSingleton();
		$sCurrentPath = $this->getPath($oDocument);

		// check if the deleted folder exists and create it if not
        $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
        $sDocumentRoot = $oConfig->get('urls/documentRoot');
	$oNewFolder = Folder::get($oDocument->getFolderID());

        $aVersions = KTDocumentContentVersion::getByDocument($oDocument);
        foreach ($aVersions as $oVersion) {
            $sNewPath = sprintf("%s/%s-%s", KTDocumentCore::_generateFolderPath($oNewFolder->getID()), $oVersion->getId(), $oVersion->getFileName());
	    $oVersion->setStoragePath($sNewPath);
            $sOldPath = sprintf("Deleted/%s-%s", $oVersion->getId(), $oVersion->getFileName());
            $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);
            $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath);
            KTUtil::moveFile($sFullOldPath, $sFullNewPath);
	    $oVersion->update();

        }
        return true;
	}


	/**
	* View a document using an inline viewer
	*
	* @param 	Primary key of document to view
	*
	* @return int number of bytes read from file on success or false otherwise;
	*
	* @todo investigate possible problem in MSIE 5.5 concerning Content-Disposition header
	*/
	function inlineViewPhysicalDocument($iDocumentID) {
            //get the document
            $oDocument = & Document::get($iDocumentID);
            //get the path to the document on the server
            $sDocumentFileSystemPath = $oDocument->getPath();
            if (file_exists($sDocumentFileSystemPath)) {
                header("Content-Type: application/octet-stream");
                header("Content-Length: ". $oDocument->getFileSize());
                // prefix the filename presented to the browser to preserve the document extension
                header('Content-Disposition: inline; filename="' . $oDocument->getFileName() . '"');
                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                header("Cache-Control: must-revalidate");
                header("Content-Location: ".$oDocument->getFileName());
                return readfile($sDocumentFileSystemPath);
            } else {
                return false;
            }
	}

	/**
	* Get the uploaded file information and place it into a document object
	*
	* @param	Array containing uploaded file information (use $aFileArray)
	* par		Primary key of folder into which document will be placed
	*
	* @return Document Document object containing uploaded file information
	*/
	function & createDocumentFromUploadedFile($aFileArray, $iFolderID) {
		//get the uploaded document information and put it into a document object
		$oDocument = new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID);
		return $oDocument;
	}
}

?>

⌨️ 快捷键说明

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