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/WemagSidebarManagement/WemagSidebarManagementPlugin.php

178 lines
5.7 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of Wemag Sidebar Management.
*
* Wemag Sidebar Management 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 Sidebar Management 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 Sidebar Management.
* If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2008 Aart-Jan Boor <aart-jan@wemag.nl>
* Wemag Advisering <http://www.wemag.nl>
*/
require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
require_once (KT_DIR.'/plugins/KTPFramework/KTPFrameworkPlugin.php');
/**
* Wrapper class for KTPage. Used for overloading some methods
* to control 'uncontrollable' interface parts.
*/
class WemagWSMPortletTrigger{
static $WSM_portlets;
static $WSM_config;
function WemagWSMPortletTrigger(){
$this->_getConfig();
}
/**
* Load configuration file (can be edited in Administration)
*
*/
function _getConfig(){
$this->WSM_portlets = array();
//determine the file path
if(isset($_GET['fDocumentId'])){
$path = KT_DIR."/plugins/WemagSidebarManagement/var/document_config.php";
}else{
$path = KT_DIR."/plugins/WemagSidebarManagement/var/folder_config.php";
}
//unserialize, because config is saved as serializes array
$this->WSM_config = unserialize(file_get_contents($path));
}
/**
* KTPage class override. This method is called for adding a portlet
* to the sidebar. By intercepting this method we can change some
* aspects of the portlet layout, and refuse to add some portlets.
* Again, this method is called by KT internal (blackbox) code.
*
* @param KTPortlet $oPortlet portlet to add
*/
function &runTrigger($oPortlet, $aPortlets){
$oPortlet->WSM_Order = 0; //place portlets on top by default
//Check if there is some special configuration for this portlet
if($this->WSM_config[md5($oPortlet->sTitle)] != null){
$config = $this->WSM_config[md5($oPortlet->sTitle)];
$oPortlet->WSM_Order = $config->order;
//collapse or open portlet?
if($config->active == 1){
$oPortlet->bActive = true;
}else{
$oPortlet->bActive = false;
}
//hide portlet completely?
if($config->delete == true){
$oPortlet->WSM_delete = true;
}
/*Does this portlet has actions?
If so, delete actions that match
the blacklisted actions in the config file */
if(count($oPortlet->actions)>0 && count($config->disabled_actions)>0){
foreach($oPortlet->actions as $key => $action){
if($config->disabled_actions[$action['ns']] == true){
unset($oPortlet->actions[$key]);
}
}
}
}
//we don't want to show deleted portlets
if($oPortlet->WSM_delete!=true){
$sortedArray = array();
$currentAdded = false;
if(count($aPortlets) == 0){
//if no portlets have been added to the sidebar yet,
//simply add this one
array_push($sortedArray,$oPortlet);
}else{
//some portlets already have been added.
//build a new portlets array and insert
// the new portlet at the right (order) position
foreach($aPortlets as $oPortletS){
if($oPortlet->WSM_Order < $oPortletS->WSM_Order && $currentAdded == false){
array_push($sortedArray,$oPortlet);
$currentAdded = true;
}
array_push($sortedArray,$oPortletS);
}
if($currentAdded == false){
//apparantly the portlet needs to be placed at the end
array_push($sortedArray,$oPortlet);
}
}
$this->WSM_portlets = $sortedArray;
//Copy our portlets array to the KT portlets array
//KT will internally handle the actual displaying
//of the portlets inside the array :-)
return $this->WSM_portlets;
}
return $aPortlets;
}
}
/**
* This plugin allows easy management of the document and folder
* sidebars in the KT interface.
*/
class WemagSidebarManagement extends KTPlugin {
var $sNamespace = "demo.WemagSidebarManagement.plugin";
/**
* Construct plugin
*
* @param string $sFilename
* @return WemagSidebarManagement plugin object
*/
function WemagSidebarManagement($sFilename = null) {
$res = parent::KTPlugin($sFilename);
$this->sFriendlyName = _kt('Wemag Sidebar Management - Manage folder and document view sidebars');
return $res;
}
/**
* Setup template path, actions, admin pages etc.
*
*/
function setup() {
//templates
$oTemplating =& KTTemplating::getSingleton();
$oTemplating->addLocation('WemagSidebarManagement', '/plugins/WemagSidebarManagement/admin/templates');
//admin area
$this->registerAdminCategory("sidebarmanagement", _kt("Sidebar Management"),
_kt("Manage the sidebar of the folder and document view."));
$this->registerAdminPage("folderportlets",'FolderPortletsDispatcher','sidebarmanagement', _kt('Folder sidebar'),
_kt('Configure folder sidebar.'), 'admin/folder_portlets.php');
$this->registerAdminPage("documentportlets",'DocumentPortletsDispatcher','sidebarmanagement', _kt('Document sidebar'),
_kt('Configure document sidebar.'), 'admin/document_portlets.php');
KTPUtil::registerAddPortletTrigger($this->sNamespace, "WemagWSMPortletTrigger", "/plugins/WemagSidebarManagement/WemagSidebarManagementPlugin.php");
}
}
$oRegistry =& KTPluginRegistry::getSingleton();
$oRegistry->registerPlugin('WemagSidebarManagement', 'demo.WemagSidebarManagement.plugin', __FILE__);
?>