This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Incam_SGD/plugins/WemagTreeBrowsePlugin/WemagTreeBrowsePlugin.php

227 lines
7.4 KiB
PHP

<?php
// Script created by Philip Arkcoll,
// modified by Rene Kanzler <rk (at) cosmomill (dot) de>
// modified by Aart-Jan Boor, Wemag Advisering, www.wemag.nl
/**
* This file is part of Wemag Tree Browse.
*
* Wemag Wemag Tree Browse is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wemag Tree Browse 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 Wemag Tree Browse. If not, see <http://www.gnu.org/licenses/>.
*/
//prevent memory shortage
ini_set('memory_limit',"512M");
require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php');
require_once(KT_LIB_DIR . '/documentmanagement/Document.inc');
/**
* Special folder action to provide tree view/ table view switching
*
*/
class WemagTreeBrowsePluginDisableEnableAction extends KTFolderAction{
var $sName = 'demo.WemagTreeBrowsePlugin.actions.folder.disableenable';
var $sPermissionName = 'ktcore.permissions.read';
function getDisplayName(){
if ($_COOKIE['kt_usetreeview']==1) {
return _kt('Vista de tabla');
} else {
return _kt('Vista de árbol');
}
}
function do_main(){
/*if (!isset($_COOKIE['kt_usetreeview'])) {
setcookie("kt_usetableview",1,time()+31536000);
}*/
if($_COOKIE['kt_usetreeview']==0){
setcookie('kt_usetreeview',1,time()+31536000);
} else {
setcookie('kt_usetreeview',1,time()-31536000);
}
header("Location: browse.php?fFolderId=".$this->oFolder->iId);
exit;
}
}
/**
* Folder action, which does not actually displays in the menu, but takes care
* of showing the tree instead of the table
*
*/
class WemagTreeBrowsePluginFolderAction extends KTFolderAction{
// The namespace for this action
var $sName = 'demo.WemagTreeBrowsePlugin.actions.folder.tree';
// The permission required to see this action on the menu
var $sPermissionName = 'ktcore.permissions.read';
//To make sure the first folder is not collapsed
var $foldercount = 0;
/**
* Check if the tree view needs to be displayed
*
*/
function getDisplayName() {
//don't show anything if table view is prefered
if ($_COOKIE['kt_usetreeview'] == 1) {
//change the menu "Browse" URL
$this->oPage->menu['browse']['url']="action.php?kt_path_info=demo.WemagTreeBrowsePlugin.actions.folder.tree&fFolderId=1";
//redirect if required
if(strpos($_SERVER['PHP_SELF'],'browse.ph')){
header("Location: action.php?kt_path_info=demo.WemagTreeBrowsePlugin.actions.folder.tree&fFolderId=".$this->oFolder->iId);
exit;
}
}
}
/**
* show the actual tree
*
* @return the tree HTML code
*/
function do_main() {
$oTemplating =& KTTemplating::getSingleton();
//only show a partial tree
if($_GET['subtree'] == 1){
$oTemplate = $oTemplating->loadTemplate('view_folder_children');
$aChildren = &$this->_getChildren($this->oFolder);
$aTemplateData = array('context' => $this,
'oFolder' => $this->oFolder,
'folders' => $aChildren['folders'],
'documents' => $aChildren['documents']);
echo $oTemplate->render($aTemplateData);
exit;
}
// Get the templating engine and load the 'view' template
$oTemplate = $oTemplating->loadTemplate('view');
// All we have to pass is the current context
$aTemplateData = array('context' => $this);
// And render. The template will call the 'renderFolder'
// method on $this.
return $oTemplate->render($aTemplateData);
}
/**
* 'renderFolder' is used by the template on each folder it gets.
*
* @param $oFolder Folder object to show
* @param boolean $children if 1 children are shown
* @return template HTML
*/
function renderFolder($oFolder, $children = true) {
$oTemplating =& KTTemplating::getSingleton();
if($children == true){
// Get the child documents and folders of the folder passed.
$aChildren = &$this->_getChildren($oFolder);
$oTemplate = $oTemplating->loadTemplate('view_folder');
}else{
$oTemplate = $oTemplating->loadTemplate('view_folder_single');
}
// And pass them, along with the folder passed, to the
// template.
$aTemplateData = array('context' => $this,
'oFolder' => $oFolder,
'folders' => $aChildren['folders'],
'documents' => $aChildren['documents']);
return $oTemplate->render($aTemplateData);
}
// '_getChildren' is a helper method that returns array of
// Document or Folder objects that are visible to the current
// user.
function &_getChildren($oFolder) {
// A BrowseQuery is the easiest way to get a list of document
// or folders visible to a user. It is passed a base folder, a
// user to check permissions against, and (optionally) an
// array of options that affect how it is performed. In this
// case, we pass no options. BrowseQuery is defined in
// /lib/browse/PartialQuery.inc.php, along with a number of
// other useful queries.
$oQuery = new BrowseQuery($oFolder->getId(), $this->oUser);
// 'getFolders' and 'getDocuments' use the same calling
// signature:
// 10000: the number of items to return
// 0: the offset from the beginning of the list (for batching)
// 'name': the column to sort on
// 'asc': the direction of the sort.
// Both functions return IDs.
// For both folders and documents, we iterate through the IDs
// returned and build an array of objects.
foreach($oQuery->getFolders(10000, 0, 'name', 'asc') as $aFolderId) {
$aFolders[] = Folder::get($aFolderId['id']);
}
foreach($oQuery->getDocuments(10000, 0, 'name', 'asc') as $aDocumentId) {
$aDocuments[] = Document::get($aDocumentId['id']);
}
return array('documents' => $aDocuments, 'folders' => $aFolders);
}
// '_mimeHelper' just calls the KTMime tool, and gets the
// appropriate name for the mime type id passed. The mime type id
// is retrieved in the template.
function _mimeHelper($iMimeTypeId) {
return KTMime::getIconPath($iMimeTypeId);
}
}
/**
* This plugin provides a tree view of the document repository,
* and allows quick and easy browsing.
*
*/
class WemagTreeBrowsePlugin extends KTPlugin {
var $sNamespace = "demo.WemagTreeBrowse.plugin";
function WemagTreeBrowsePlugin($sFilename = null) {
$res = parent::KTPlugin($sFilename);
$this->sFriendlyName = _kt('Wemag Tree Browse Plugin - AJAX folder tree view plugin');
return $res;
}
function setup() {
$oTemplating =& KTTemplating::getSingleton();
$oTemplating->addLocation('WemagTreeBrowsePlugin', '/plugins/WemagTreeBrowsePlugin/templates');
$this->registerAction('folderaction', 'WemagTreeBrowsePluginFolderAction', 'demo.WemagTreeBrowsePlugin.actions.folder.tree');
$this->registerAction('folderaction', 'WemagTreeBrowsePluginDisableEnableAction', 'demo.WemagTreeBrowsePlugin.actions.folder.disableenable');
}
}
$oRegistry =& KTPluginRegistry::getSingleton();
$oRegistry->registerPlugin('WemagTreeBrowsePlugin', 'demo.WemagTreeBrowse.plugin', __FILE__);
?>