Browse Source

re add pluginmanager

develop
o.pinke 4 months ago
parent
commit
f6bd3e0b22
100 changed files with 16270 additions and 1 deletions
  1. +4
    -1
      .gitignore
  2. +212
    -0
      conlite/plugins/pluginmanager/classes/Util/Zip/Contenido_ArchiveExtractor.class.php
  3. +143
    -0
      conlite/plugins/pluginmanager/classes/Util/Zip/class.pim.plugin.archive.extractor.php
  4. +55
    -0
      conlite/plugins/pluginmanager/classes/Util/class.pim.sql.parser.php
  5. +28
    -0
      conlite/plugins/pluginmanager/classes/class.pim.ajax.php
  6. +34
    -0
      conlite/plugins/pluginmanager/classes/class.pim.plugin.dummy.php
  7. +271
    -0
      conlite/plugins/pluginmanager/classes/class.pim.plugin.handler.php
  8. +34
    -0
      conlite/plugins/pluginmanager/classes/class.pim.plugin.php
  9. +58
    -0
      conlite/plugins/pluginmanager/classes/class.pim.plugin.relation.php
  10. +83
    -0
      conlite/plugins/pluginmanager/classes/class.pim.view.php
  11. +104
    -0
      conlite/plugins/pluginmanager/classes/class.pluginmanager.ajax.php
  12. +46
    -0
      conlite/plugins/pluginmanager/classes/exeptions/class.pim.exeption.php
  13. +67
    -0
      conlite/plugins/pluginmanager/classes/plugin/class.plugin.handler.abstract.php
  14. +19
    -0
      conlite/plugins/pluginmanager/classes/plugin/interface.plugins.php
  15. +357
    -0
      conlite/plugins/pluginmanager/classes/setup/class.pim.setup.base.php
  16. +427
    -0
      conlite/plugins/pluginmanager/classes/setup/class.pim.setup.plugin.install.php
  17. +38
    -0
      conlite/plugins/pluginmanager/classes/setup/class.pim.setup.plugin.uninstall.php
  18. BIN
      conlite/plugins/pluginmanager/css/images/error.png
  19. BIN
      conlite/plugins/pluginmanager/css/images/info.png
  20. BIN
      conlite/plugins/pluginmanager/css/images/success.png
  21. BIN
      conlite/plugins/pluginmanager/css/images/warning.png
  22. +101
    -0
      conlite/plugins/pluginmanager/css/pluginmanager.css
  23. BIN
      conlite/plugins/pluginmanager/docs/Dokumentation Contenido Plugin Manager.pdf
  24. +42
    -0
      conlite/plugins/pluginmanager/docs/install.sql
  25. BIN
      conlite/plugins/pluginmanager/docs/linkchecker.zip
  26. +2
    -0
      conlite/plugins/pluginmanager/docs/localize.txt
  27. +1434
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive.php
  28. +57
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate.php
  29. +87
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/And.php
  30. +52
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Current.php
  31. +88
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Custom.php
  32. +116
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Duplicate.php
  33. +59
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Ereg.php
  34. +61
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Eregi.php
  35. +71
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Extension.php
  36. +47
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/False.php
  37. +62
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Index.php
  38. +75
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/MIME.php
  39. +63
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/MaxDepth.php
  40. +59
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/MinSize.php
  41. +63
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/MinTime.php
  42. +55
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Not.php
  43. +85
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/Or.php
  44. +45
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Predicate/True.php
  45. +427
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader.php
  46. +387
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Ar.php
  47. +98
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Archive.php
  48. +254
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Bzip2.php
  49. +262
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Cache.php
  50. +136
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/ChangeName.php
  51. +89
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/ChangeName/AddDirectory.php
  52. +52
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/ChangeName/Callback.php
  53. +100
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/ChangeName/Directory.php
  54. +195
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Concat.php
  55. +309
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Directory.php
  56. +296
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/File.php
  57. +90
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Filter.php
  58. +276
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Gzip.php
  59. +227
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Memory.php
  60. +939
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/MimeList.php
  61. +95
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Multi.php
  62. +134
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Relay.php
  63. +63
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Select.php
  64. +412
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Tar.php
  65. +317
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Uncompress.php
  66. +482
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Reader/Zip.php
  67. +119
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer.php
  68. +102
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/AddBaseName.php
  69. +209
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Ar.php
  70. +129
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Archive.php
  71. +147
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Bzip2.php
  72. +259
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Files.php
  73. +139
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Gzip.php
  74. +204
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Mail.php
  75. +127
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Memory.php
  76. +213
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/MemoryArchive.php
  77. +130
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Multi.php
  78. +93
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Output.php
  79. +244
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Tar.php
  80. +143
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/UniqueAppender.php
  81. +260
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Archive/Writer/Zip.php
  82. +197
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Iterator.php
  83. +155
    -0
      conlite/plugins/pluginmanager/docs/pear/File/Iterator/Factory.php
  84. +523
    -0
      conlite/plugins/pluginmanager/docs/pear/MIME/Type.php
  85. +298
    -0
      conlite/plugins/pluginmanager/docs/pear/MIME/Type/Extension.php
  86. +163
    -0
      conlite/plugins/pluginmanager/docs/pear/MIME/Type/Parameter.php
  87. +30
    -0
      conlite/plugins/pluginmanager/includes/config.autoloader.php
  88. +16
    -0
      conlite/plugins/pluginmanager/includes/config.plugin.php
  89. +200
    -0
      conlite/plugins/pluginmanager/includes/functions/simplexml_dump.php
  90. +249
    -0
      conlite/plugins/pluginmanager/includes/functions/simplexml_tree.php
  91. +221
    -0
      conlite/plugins/pluginmanager/includes/include.right_bottom.php
  92. BIN
      conlite/plugins/pluginmanager/locale/de_DE/LC_MESSAGES/pluginmanager.mo
  93. +236
    -0
      conlite/plugins/pluginmanager/locale/de_DE/LC_MESSAGES/pluginmanager.po
  94. +215
    -0
      conlite/plugins/pluginmanager/locale/pluginmanager.pot
  95. +26
    -0
      conlite/plugins/pluginmanager/locale/potfiles.txt
  96. +176
    -0
      conlite/plugins/pluginmanager/scripts/jquery.plainmodal.js
  97. +1
    -0
      conlite/plugins/pluginmanager/scripts/jquery.plainmodal.min.js
  98. +426
    -0
      conlite/plugins/pluginmanager/scripts/jquery.plainoverlay.js
  99. +1
    -0
      conlite/plugins/pluginmanager/scripts/jquery.plainoverlay.min.js
  100. +275
    -0
      conlite/plugins/pluginmanager/scripts/pluginmanager.js

+ 4
- 1
.gitignore View File

@@ -1 +1,4 @@
/nbproject/private/
/nbproject/private/
/data/config/production/config.php
/_dev/
/conlite/plugins/pluginmanager/_src/

+ 212
- 0
conlite/plugins/pluginmanager/classes/Util/Zip/Contenido_ArchiveExtractor.class.php View File

@@ -0,0 +1,212 @@
<?php
/**
* Project:
* Contenido Content Management System
*
* Description:
* Extractor for plugin archive files
*
* Requirements:
* @con_php_req 5.0
*
*
* @package Contenido Backend plugins
* @version 1.0.0
* @author Dominik Ziegler
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
* @since file available since contenido release 4.8.7
*
* {@internal
* created 2008-06-06
* modified 2008-07-03, Frederic Schneider, add security fix
*
* $Id: Contenido_ArchiveExtractor.class.php 7 2015-06-23 11:01:26Z oldperl $:
* }}
*
*/

if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

plugin_include('pluginmanager', 'classes/Exceptions/Contenido_ArchiveExtractor_Exception.php');
//cInclude('pear', 'PHP/Archive.php');
cInclude('pear', 'File/Archive.php');

class Contenido_ArchiveExtractor {

/**
* The archive file
* @var string
*/
protected $sSource = "";

/**
* The destination path
* @var string
*/
protected $sDestination = "";

/**
* List of all files in the archive
* @var array
*/
protected $aFileList = array();

/**
* The absolute path
* @var string
*/
protected $sAbsPath = "";

/**
* Constructor of ArchiveExtractor, load the file list
* @access public
* @param string $sSource
* @return void
*/
public function __construct($sSource) {
global $cfg;

$this->sSource = (string) $sSource;

if (file_exists($sSource)) {

$sTrailingSlash = substr($this->sSource, -1);

if( $sTrailingSlash != DIRECTORY_SEPARATOR) {
$this->sSource = $this->sSource . DIRECTORY_SEPARATOR;
}

// generate absolute path to the plugin manager directory
$this->sAbsPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . "pluginmanager" . DIRECTORY_SEPARATOR;

$this->getFileList();

} else {
throw new Contenido_ArchiveExtractor_Exception("Source file does not exists");
}

}

public function setErrorHandling($mode, $options) {
PEAR::setErrorHandling($mode, $options); // use temporary the error handler of PEAR
}

/**
* Sets the path where the extractor extracts the archive files
* @access public
* @param string $sDestination
* @return void
*/
public function setDestinationPath($sDestination) {

if (!is_dir($sDestination)) {
$bMakeDirectory = mkdir($sDestination, 0777);

if ($bMakeDirectory != true) {
throw new Contenido_ArchiveExtractor_Exception("Can not set destination path: directoy is not writable");
}

$this->sDestination = (string) $sDestination;

} else {
throw new Contenido_ArchiveExtractor_Exception("Destination already exists");
}

}

/**
* Extracts the whole archive
* @access public
* @return void
*/
public function extractArchive() {

if ($this->sDestination != "") {
File_Archive::extract($this->sSource, $this->sDestination);
} else {
throw new Contenido_ArchiveExtractor_Exception("Extraction failed: no destination path setted");
}

}

/**
* Loads the file list of the archive
* @access public
* @return void
*/
public function getFileList(){
$objArchiveReader = File_Archive::read($this->sSource);
$this->aFileList = $objArchiveReader->getFileList();
}

/**
* Extract only one specific file from archive
* @access public
* @param string $sFilename
* @return void
*/
public function extractArchiveFile($sFilename) {

$sFilename = (string) $sFilename;
$sExtractFile = $this->sSource . $sFilename;

if ($this->sDestination != "") {
File_Archive::extract($sExtractFile, $this->sDestination);
} else {
throw new Contenido_ArchiveExtractor_Exception("Extraction failed: no destination path setted");
}

}

/**
* Returns the archives file list
* @access public
* @return array
*/
public function getArchiveFileList() {
return $this->aFileList;
}

/**
* Checks if a specific file exists in archive
* @access public
* @param string $sFilename
* @return boolean
*/
public function existsInArchive($sFilename) {

$aFileList = $this->getArchiveFileList();

if (in_array($sFilename, $aFileList)) {
$bFileCheck = true;
} else {
$bFileCheck = false;
}

return $bFileCheck;

}

/**
* Extracts a specific file from archive and return its content to use it in a variable
* @access public
* @param string $sFilename
* @return string
*/
public function extractArchiveFileToVariable($sFilename) {

$sFilename = (string) $sFilename;
$sExtractFile = $this->sSource . $sFilename;

File_Archive::extract($sExtractFile, File_Archive::toVariable($sReturn));
return $sReturn;
}

}
?>

+ 143
- 0
conlite/plugins/pluginmanager/classes/Util/Zip/class.pim.plugin.archive.extractor.php View File

@@ -0,0 +1,143 @@
<?php
if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
class pimPluginArchiveExtractor {
/**
* The extractor initializer
*
* @var int
*/
protected $_extractor = 0;
/**
* The temp dir
*
* @var string
*/
protected $tempDir = '';
/**
* The archive file
*
* @var string
*/
protected $_source = '';
/**
* The destination path
*
* @var string
*/
protected $_destination = '';
/**
* The absolute path
*
* @var string
*/
protected $_absPath = '';
/**
*
* @param string $source
* @param string $filename
* @throws pimException
*/
public function __construct($source, $filename) {
$cfg = cRegistry::getConfig();
// initialzing ziparchive
$this->_extractor = new ZipArchive();
// path to temp directory
$this->tempDir = $source;
// temp directory with zip archive
$this->_source = (string) $source . (string) $filename;
if (file_exists($source)) {
// generate absolute path to the plugin manager directory
$this->_absPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . 'pluginmanager' . DIRECTORY_SEPARATOR;
// open the zip archive
$this->_extractor->open($this->_source);
} else {
throw new pimException('Source file does not exists');
}
}
public function closeArchive() {
$this->_extractor->close();
}
/**
*
* @param string $destination
* @throws pimException
*/
public function setDestinationPath($destination) {
if (!is_dir($destination)) {
$makeDirectory = mkdir($destination, 0777);
if ($makeDirectory != true) {
throw new pimException('Can not set destination path: directoy is not writable');
}
$this->_destination = (string) $destination;
} else {
throw new pimException('Destination already exists');
}
}
/**
*
* @throws pimException
*/
public function extractArchive() {
if ($this->_destination != '') {
$this->_extractor->extractTo($this->_destination);
} else {
throw new pimException('Extraction failed: no destination path setted');
}
}
/**
*
* @param string $filename
* @param boolean $content
* @return type
*/
public function extractArchiveFileToVariable($filename, $content = true) {
$filename = (string) $filename;
$this->_extractor->extractTo($this->tempDir, $filename);
if ($content) {
return file_get_contents($this->tempDir . $filename);
} else {
return $this->tempDir . $filename;
}
}
/**
*
*/
public function destroyTempFiles() {
// remove plugin.xml if exists
if (file_exists($this->tempDir . 'cl_plugin.xml')) {
unlink($this->tempDir . 'cl_plugin.xml');
}
// remove plugin_install.sql if exists
if (file_exists($this->tempDir . 'plugin_install.sql')) {
unlink($this->tempDir . 'plugin_install.sql');
}
// remove temporary plugin dir if exists
if (file_exists($this->_source)) {
unlink($this->_source);
}
}
}

+ 55
- 0
conlite/plugins/pluginmanager/classes/Util/class.pim.sql.parser.php View File

@@ -0,0 +1,55 @@
<?php

class pimSqlParser {

public static function removeComments($sSqlData) {
$sRegEx = '@(([\'"]).*?[^\\\]\2)|((?:\#|--).*?$|/\*(?:[^/*]|/(?!\*)|\*(?!/)|(?R))*\*\/)\s*|(?<=;)\s+@ms';

$sCleanSqlData = trim(preg_replace($sRegEx, '$1', $sSqlData));

//Eventually remove the last ;
if(strrpos($sCleanSqlData, ";") === strlen($sCleanSqlData) - 1) {
$sCleanSqlData = substr($sCleanSqlData, 0, strlen($sCleanSqlData) - 1);
}

return $sCleanSqlData;
}
public static function replacePlaceholder($sData) {
return str_replace(pimSetupBase::PIM_SQL_PLACEHOLDER, cRegistry::getConfigValue('sql', 'sqlprefix')."_pi", $sData);
}

public static function parse($sSqlData) {
$aSingleQueries = array();
$sSqlData = pimSqlParser::replacePlaceholder($sSqlData);
// Processing the SQL file content
$lines = explode("\n", $sSqlData);

$sQuery = "";
// Parsing the SQL file content
foreach ($lines as $sql_line):
$sql_line = trim($sql_line);
if($sql_line === "") continue;
else if(strpos($sql_line, "--") === 0) continue;
else if(strpos($sql_line, "#") === 0) continue;
$sQuery .= $sql_line;
// Checking whether the line is a valid statement
if (preg_match("/(.*);/", $sql_line)) {
$sQuery = trim($sQuery);
$sQuery = substr($sQuery, 0, strlen($sQuery) - 1);

$sQuery = pimSqlParser::removeComments($sQuery);
//store this query
$aSingleQueries[] = $sQuery;
//reset the variable
$sQuery = "";
}
endforeach;

return $aSingleQueries;
}
}

+ 28
- 0
conlite/plugins/pluginmanager/classes/class.pim.ajax.php View File

@@ -0,0 +1,28 @@
<?php
/**
* $Id: class.pim.ajax.php 29 2016-10-18 11:27:53Z oldperl $:
*/

if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

abstract class pimAjax{
/**
* constructor
*/
public function __construct() {
;
}
/**
* Handles the ajax request named bei param and returns an answer string
* child class has to overwrite this method
*
* @param string $Request requested ajax action
* @return string String send back to requesting page
*/
abstract public function handle($Request);
}
?>

+ 34
- 0
conlite/plugins/pluginmanager/classes/class.pim.plugin.dummy.php View File

@@ -0,0 +1,34 @@
<?php
/**
*
*/

// security check
defined('CON_FRAMEWORK') or die('Illegal call');


class pimPluginDummy {
public function __construct() {
;
}
public function get($what) {
$return = FALSE;
switch($what) {
case 'folder':
$return = 'pluginmanager';
break;
case 'active':
$return = TRUE;
break;
}
return $return;
}
public function isLoaded() {
return TRUE;
}
}
?>

+ 271
- 0
conlite/plugins/pluginmanager/classes/class.pim.plugin.handler.php View File

@@ -0,0 +1,271 @@
<?php

/**
*
* @version $Rev: 39 $
*
* $Id: class.pim.plugin.handler.php 39 2018-01-10 07:49:57Z oldperl $
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

class pimPluginHandler {

protected $_iPluginId = 0;
protected $_oPlugin = NULL;
protected $_bIsLoaded = FALSE;
protected $_sPluginPath;

/**
* holds the xml of plugin.xml
* @var SimpleXMLElement
*/
protected $_oPiXml = NULL;

/**
*
* @var DomDocument
*/
protected $_oDomDocument;
protected $_xsd = 'plugins/pluginmanager/xml/plugin_info.xsd';
protected $_bValid = FALSE;

/**
* Constructor
*/
public function __construct() {
$this->_oDomDocument = new DOMDocument();
$this->_oDomDocument->preserveWhiteSpace = FALSE;
}

/**
*
* @param int $iPluginId
* @return boolean
*/
public function loadPluginFromDb($iPluginId) {
$this->_oPlugin = new pimPlugin($iPluginId);
if ($this->_oPlugin->isLoaded()) {
$this->_iPluginId = $this->_oPlugin->get('idplugin');
$this->_sPluginPath = cRegistry::getBackendPath()
. cRegistry::getConfigValue('path', 'plugins')
. $this->_oPlugin->get('folder')
. "/";
return TRUE;
}
$this->_oPlugin = NULL;
return FALSE;
}

/**
*
* @param string $sPluginFolderName
* @return boolean
*/
public function installPlugin($sPluginFolderName) {
$iNewPluginId = 0;
if (empty($sPluginFolderName)) {
return FALSE;
}
$pluginPath = cRegistry::getBackendPath()
. cRegistry::getConfigValue('path', 'plugins')
. $sPluginFolderName
. "/";

if (is_null($this->getCfgXmlObject())) {
$sPiCfg = $pluginPath . 'cl_plugin.xml';
if (is_dir($pluginPath) && file_exists($sPiCfg)) {
$this->loadXmlFile($sPiCfg);
} else {
return FALSE;
}
}

$oPluginInstaller = new pimSetupPluginInstall();
$oPluginInstaller->setXsdFile($this->_xsd);
$oPluginInstaller->setXmlObject($this->getCfgXmlObject());
$oPluginInstaller->setPluginPath($pluginPath);
$this->_iPluginId = $oPluginInstaller->installPlugin();
if ($this->_iPluginId > 0) {
return TRUE;
}
return FALSE;
}

/**
*
* @param string $sHandleSql
* @return boolean
*/
public function uninstallPlugin($sHandleSql) {
$oPluginUninstall = new pimSetupPluginUninstall();
$oPluginUninstall->setPluginPath($this->_sPluginPath);
return $oPluginUninstall->uninstallPlugin($this->_iPluginId, $sHandleSql);
}

/**
*
* @return int
*/
public function getPluginId() {
return $this->_iPluginId;
}

/**
*
* @param string $sFile
* @return boolean
*/
public function loadXmlFile($sFile) {
$this->_oDomDocument->load($sFile);
if ($this->_validateXml()) {
$this->_oPiXml = simplexml_load_string($this->_oDomDocument->C14N());
}
return (is_a($this->_oPiXml, "SimpleXMLElement")) ? TRUE : FALSE;
}

/**
*
* @return object|null
*/
public function getCfgXmlObject() {
if (is_object($this->_oPiXml)) {
return $this->_oPiXml;
}
return NULL;
}

/**
*
* @return array
*/
public function getPiGeneralArray() {
$aGeneral = array();
if (is_object($this->_oPiXml)) {
$aGeneral = $this->_xml2Array($this->_oPiXml->general);
if($aDependencies = $this->_getDepencyArray()) {
foreach ($aDependencies as $aDependency) {
}
}
$aGeneral['dependencies'] = print_r($aDependencies, TRUE);
}
return $aGeneral;
}

/**
* Returns generated list entry (li) for plugin or empty string
*
* @param int $iPluginId
* @return string
*/
public function getInfoInstalled($iPluginId) {
$oPlugin = new pimPlugin($iPluginId);
if ($oPlugin->isLoaded()) {
$oView = new pimView();
$oView->setMultiVariables($oPlugin->toArray());
$aLang = array(
'LANG_FOLDERNAME' => i18n("Foldername", "pluginmanager"),
'LANG_AUTHOR' => i18n("Author", "pluginmanager"),
'LANG_CONTACT' => i18n("Contact", "pluginmanager"),
'LANG_LICENSE' => i18n("License", "pluginmanager"),
'LANG_INSTALLED' => i18n('Installed since', 'pluginmanager'),
'LANG_DEPENDENCIES' => i18n("Dependencies", "pluginmanager"),
'LANG_WRITEABLE' => i18n("Writable", "pluginmanager"),
'LANG_INSTALL' => i18n("Install", "pluginmanager"),
'LANG_REMOVE' => i18n("Remove", "pluginmanager"),
'LANG_UPDATE' => i18n('Update', 'pluginmanager'),
'LANG_UPDATE_CHOOSE' => i18n('Please choose your new file', 'pluginmanager'),
'LANG_UPDATE_UPLOAD' => i18n('Update', 'pluginmanager'),
'LANG_REMOVE_SQL' => i18n('Execute uninstall.sql', 'pluginmanager')
);
$oView->setMultiVariables($aLang);
// nav sub placeholder, @Todo: fill with content
$oView->set('s', 'NAVSUB', '');
// enable / disable functionality
$activeStatus = $oPlugin->get('active');
$oButton = new cHTMLButton('toggle_active');
$oButton->setID("but-toggle-plugin-" . $oPlugin->get("idplugin"));
$oButton->setClass("pimImgBut");
$oButton->setMode('image');
$oButtonLabel = new cHTMLLabel("placeholder", $oButton->getID());
$oButtonLabel->setClass("pimButLabel");
if ($activeStatus == 1) {
$oButton->setAlt("Click to toggle status");
$oButton->setImageSource('images/online.gif');
$oButtonLabel->setLabelText(i18n("Plugin is active", "pluginmanager"));
} else {
$oButton->setImageSource('images/offline.gif');
$oButtonLabel->setLabelText(i18n("Plugin not active", "pluginmanager"));
}
$oView->set('s', 'BUT_ACTIVESTATUS', $oButton->render() . '&nbsp;' . $oButtonLabel->render());

// update button - not used right now
$oView->set('s', 'BUT_UPDATE_PLUGIN', '');

// uninstall
$oDelBut = new cHTMLButton('uninstall_plugin');
$oDelBut->setImageSource('images/but_cancel.gif');
$oDelBut->setID("but-uninstall-plugin-" . $oPlugin->get("idplugin"));
$oDelBut->setClass("pimImgBut");
$oDelBut->setMode('image');
$oDelSqlCheckbox = new cHTMLCheckbox("delete_sql", "TRUE");
$oDelSqlCheckbox->setStyle("display: inline-block;");
$sDelSqlTxt = " " . sprintf(i18n("(%s remove database tables)", "pluginmanager"), $oDelSqlCheckbox->toHtml(FALSE));
$oDelButLabel = new cHTMLLabel("placeholder", $oDelBut->getID());
$oDelButLabel->setClass("pimButLabel");
$oDelButLabel->setLabelText(i18n("Uninstall Plugin", "pluginmanager") . $sDelSqlTxt);
$oView->set('s', 'BUT_UNINSTALL_PLUGIN', $oDelBut->render() . '&nbsp;' . $oDelButLabel->render());

$oView->setTemplate('pi_manager_installed_plugins.html');
return $oView->getRendered(1);
}
return '';
}

protected function _getDepencyArray() {
$aDependencies = array();
$aAttributes = array();
$iCountDependencies = count($this->_oPiXml->dependencies);
if($iCountDependencies > 0) {
for ($i = 0; $i < $iCountDependencies; $i++) {
$sPluginName = cSecurity::escapeString($this->_oPiXml->dependencies[$i]->depend);
foreach ($this->_oPiXml->dependencies[$i]->depend->attributes() as $sKey => $sValue) {
$aAttributes[$sKey] = cSecurity::escapeString($sValue);
}
$aDependencies[$i]["name"] = $sPluginName;
$aDependencies[$i] = array_merge($aDependencies[$i],$aAttributes);
}
return $aDependencies;
}
return FALSE;
}

/**
*
* @return boolean
* @throws pimXmlStructureException
*/
private function _validateXml() {
if ($this->_oDomDocument->schemaValidate($this->_xsd)) {
$this->_bValid = true;
return true;
} else {
return FALSE;
}
}

/**
*
* @param xml $xml
* @return array
*/
private function _xml2Array($xml) {
$string = json_encode($xml);
$array = json_decode($string, true);
return $array;
}

}

+ 34
- 0
conlite/plugins/pluginmanager/classes/class.pim.plugin.php View File

@@ -0,0 +1,34 @@
<?php
/**
*
*/

// security check
defined('CON_FRAMEWORK') or die('Illegal call');

/**
* Description of class.pim.plugin
*
* @author Ortwin Pinke <o.pinke@php-backoffice.de>
*/
class pimPluginCollection extends ItemCollection {
public function __construct() {
global $cfg;
parent::__construct($cfg['tab']['plugins'], 'idplugin');
$this->_setItemClass("pimPlugin");
}
}

class pimPlugin extends Item {
public function __construct($mId = false) {
global $cfg;
parent::__construct($cfg['tab']['plugins'], 'idplugin');
if ($mId !== false) {
$this->loadByPrimaryKey($mId);
}
}
}
?>

+ 58
- 0
conlite/plugins/pluginmanager/classes/class.pim.plugin.relation.php View File

@@ -0,0 +1,58 @@
<?php
/**
*
*/

// security check
defined('CON_FRAMEWORK') or die('Illegal call');

/**
* Description of class.pim.plugin
*
* @author Ortwin Pinke <o.pinke@php-backoffice.de>
*/
class pimPluginRelationCollection extends ItemCollection {
const REL_AREA = 'area';
const REL_ACTION = 'action';
const REL_NAVS = 'navs';
const REL_CTYPE = 'ctype';
public function __construct() {
global $cfg;
parent::__construct($cfg['tab']['plugins_rel'], 'idpluginrelation');
$this->_setItemClass("pimPluginRelation");
}
public function create($idItem, $idPlugin, $type) {
// create a new entry
$item = parent::create();
$item->set('iditem', $idItem);
$item->set('idplugin', $idPlugin);
$item->set('type', $type);

$item->store();
return $item;
}
public function getRelations($idPlugin, $type=NULL) {
return;
}
public function deleteRelations($idPlugin, $type=NULL) {
return;
}
}

class pimPluginRelation extends Item {

public function __construct($mId = false) {
global $cfg;
parent::__construct($cfg['tab']['plugins_rel'], 'idpluginrelation');
if ($mId !== false) {
$this->loadByPrimaryKey($mId);
}
}
}
?>

+ 83
- 0
conlite/plugins/pluginmanager/classes/class.pim.view.php View File

@@ -0,0 +1,83 @@
<?php
/**
* Project:
* Contenido Content Management System
*
* Description:
* Backend View of Contenido PluginManager
*
* Requirements:
* @con_php_req 5.0
*
*
* @package Contenido Backend plugins
* @version 1.0.0
* @author Rudi Bieller
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
* @since file available since contenido release 4.8.7
*
* {@internal
* created 2008-03-17
* modified 2008-07-04, Frederic Schneider, add security fix and tpl settings
*
* $Id: class.pim.view.php 11 2015-07-14 12:34:24Z oldperl $:
* }}
*
*/

if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

class pimView extends Template{
protected $sPathToTpl;
protected $bIsGenerated;
protected $_sTplPath;
public function __construct($tags = false, $parser = false) {
$this->reset();
$this->set('s', 'SESSID', cRegistry::getSessionId());
$this->bIsGenerated = false;
$this->_sTplPath = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."templates".DIRECTORY_SEPARATOR;
parent::__construct($tags, $parser);
}
public function setTemplate($sTplName) {
$this->sPathToTpl = $this->_sTplPath.$sTplName;
}
public function setMultiVariables($aVariables) {
if(is_array($aVariables)) {
foreach($aVariables as $sName=>$sContent) {
if(is_numeric($sName)) {
continue;
}
$this->setVariable($sContent, strtoupper($sName));
}
}
}

public function setVariable($sVariable, $sName = '') {
if(empty($sName)) {
$sName = strtoupper($$sVariable);
}
$this->set('s', $sName, $sVariable);
}

public function getRendered($mode = '') {
$this->bIsGenerated = true;
return $this->generate($this->sPathToTpl, $mode);
}
public function __destruct() {
if ($this->bIsGenerated === false) {
$this->generate($this->sPathToTpl, true, false);
}
}

}
?>

+ 104
- 0
conlite/plugins/pluginmanager/classes/class.pluginmanager.ajax.php View File

@@ -0,0 +1,104 @@
<?php
/**
* $Id:$
*/

if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}


class PluginmanagerAjax extends pimAjax {
/**
*
* @param string $Request
* @return string
*/
public function handle($Request) {
$sString = '';
switch ($Request) {
// toggle active/inactive of plugins
case 'toggle_active':
if(!isset($_POST['plugin_id']) || empty($_POST['plugin_id'])) {
$sString = "Error:missing plugin id! (Err20)";
break;
}
$iPluginId = (int) $_POST['plugin_id'];
$oPlugin = new pimPlugin($iPluginId);
if($oPlugin->isLoaded()) {
$iCurrentStat = (int) $oPlugin->get('active');
$iNewStat = ($iCurrentStat == 1)?0:1;
$oPlugin->set('active', $iNewStat);
if($oPlugin->store()) {
$sString = "Ok:".$iNewStat;
if($iNewStat) {
$sString .= ":".i18n("Plugin is active", "pluginmanager");
} else {
$sString .= ":".i18n("Plugin not active", "pluginmanager");
}
break;
}
}
$sString = "Error:no changes! (Err21)";
break;
// save sortorder of plugins
case 'pim_save_sort':
parse_str($_REQUEST['plugins'], $aPlugins);
//print_r($aPlugins['plugin']);
if(is_array($aPlugins['plugin']) && count($aPlugins['plugin']) > 0) {
foreach($aPlugins['plugin'] as $sortorder=>$pluginid) {
$oPlugin = new pimPlugin($pluginid);
$oPlugin->set('executionorder', $sortorder);
$oPlugin->store();
}
}
$sString = "Ok:executionorder saved";
break;
// install plugin with existing source in plugin dir
case 'pim_install':
//sleep(3);
$iNewPluginId = 0;
$sPluginPath = cRegistry::getBackendPath()
.cRegistry::getConfigValue('path', 'plugins')
.Contenido_Security::escapeDB($_POST['plugin_folder']).DIRECTORY_SEPARATOR;
if(is_dir($sPluginPath) && is_readable($sPluginPath."cl_plugin.xml")) {
$oPluginHandler = new pimPluginHandler();
if($oPluginHandler->loadXmlFile($sPluginPath."cl_plugin.xml")) {
if($oPluginHandler->installPlugin(Contenido_Security::escapeDB($_POST['plugin_folder']))) {
$iNewPluginId = $oPluginHandler->getPluginId();
if($iNewPluginId > 0) {
$sString = "Ok:".$iNewPluginId.":Plugin successfully installed!";
} else {
$sString = "Error:".$iNewPluginId.":Plugin not installed! (Err10)";
}
} else {
$sString = "Error:0:Plugin not installed! (Err12)";
}
} else {
$sString = "Error:0:Plugin xml-file missing or not correct! (Err13)";
}
break;
}
$sString = "Error:0:Plugin folder missing or no readable xml-file found! (Err14)";
break;
// return info about installed plugin
case 'pim_get_info_installed':
$oPluginHandler = new pimPluginHandler();
$sString = $oPluginHandler->getInfoInstalled((int) $_POST['plugin_id']);
break;
//if action is unknown generate error message
default:
$sString = "Unknown Ajax Action! (Err01)";
break;
}
return $sString;
}

}

+ 46
- 0
conlite/plugins/pluginmanager/classes/exeptions/class.pim.exeption.php View File

@@ -0,0 +1,46 @@
<?php
if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

class pimExeption extends Exception {
protected $_log_exception = true;
protected $_logger = NULL;
public function __construct($message, $code = 0, Exception $previous = NULL) {
parent::__construct($message, $code, $previous);

// create a logger class and save it for all logging purposes
$writer = cLogWriter::factory("File", array(
'destination' => cRegistry::getConfigValue('path', 'data')
. 'logs/exception.log'
));
$this->_logger = new cLog($writer);

// determine if exception should be logged
if (false === $this->_log_exception
&& !is_null(cRegistry::getConfigValue('debug', 'log_exeptions'))) {
$this->_log_exception = cRegistry::getConfigValue('debug', 'log_exeptions');
}

// log the exception if it should be logged
if (true === $this->_log_exception) {
$this->log();
}
}
public function log() {
// construct the log message with all infos and write it via the logger
$logMessage = get_class($this) . ' thrown at line ' . $this->getLine() . ' of file ' . $this->getFile() . ".\r\n";
$logMessage .= 'Exception message: ' . $this->getMessage() . "\r\n";
$logMessage .= "Call stack:\r\n";
$logMessage .= $this->getTraceAsString();
$logMessage .= "\r\n";
$this->_logger->log($logMessage);
}
}

class pimXmlStructureException extends pimExeption {
}

+ 67
- 0
conlite/plugins/pluginmanager/classes/plugin/class.plugin.handler.abstract.php View File

@@ -0,0 +1,67 @@
<?php
/**
*
*/

if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

/**
*
*/
abstract class pluginHandlerAbstract implements Plugins {
/**
* Holds path to plugin dir
* @var string
*/
protected static $_piPath;
/**
*
* @var string
*/
protected static $_piUrl;
/**
* Holds template name
* @var string
*/
protected static $_piTemplate = "default";
/**
* Returns the name of the plugin directory
* @return string
*/
public static function getName() {
return basename(self::_getDir());
}
/**
* Returns the absolute server path
* @return string
*/
public static function getPath() {
return self::_getDir().DIRECTORY_SEPARATOR;
}
public static function getIncludesPath() {
return self::_getDir().DIRECTORY_SEPARATOR."includes".DIRECTORY_SEPARATOR;
}
public static function getTplPath() {
return self::_getDir().DIRECTORY_SEPARATOR."templates".DIRECTORY_SEPARATOR.self::$_piTemplate.DIRECTORY_SEPARATOR;
}
public static function getUrl() {
;
}
protected static function _getDir() {
if(empty(self::$_piPath)) {
$oReflector = new ReflectionClass(get_called_class());
self::$_piPath = dirname(dirname($oReflector->getFileName()));
}
return self::$_piPath;
}
}

+ 19
- 0
conlite/plugins/pluginmanager/classes/plugin/interface.plugins.php View File

@@ -0,0 +1,19 @@
<?php
/**
*
*/

if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

/**
*
*/
interface Plugins {
public static function getPath();
public static function getUrl();
public static function getIncludesPath();
public static function getTplPath();
}

+ 357
- 0
conlite/plugins/pluginmanager/classes/setup/class.pim.setup.base.php View File

@@ -0,0 +1,357 @@
<?php

/**
*
*/
class pimSetupBase {

/**
* name of plugin info xml file
*/
const PIM_XML_FILENAME = "cl_plugin.xml";

/**
* placeholder for sql prefix
*/
const PIM_SQL_PLACEHOLDER = "!PREFIX!";

/**
*
* @var int mode of setup
*/
public static $mode;

/**
* plugin general infos
* @var SimpleXMLElement
*/
public static $XmlGeneral;

/**
* plugin requirements
* @var SimpleXMLElement
*/
public static $XmlRequirements;

/**
* plugin depencies
* @var SimpleXMLElement
*/
public static $XmlDependencies;

/**
* areas for plugin
* @var SimpleXMLElement
*/
public static $XmlArea;

/**
* actions for plugin
* @var SimpleXMLElement
*/
public static $XmlActions;

/**
* frames for plugin - frame and framefile entries
* @var SimpleXMLElement
*/
public static $XmlFrames;

/**
* nav main entry
* @var SimpleXMLElement
*/
public static $XmlNavMain;

/**
* nav sub entries
* @var SimpleXMLElement
*/
public static $XmlNavSub;

/**
* content type(s) for plugin
* @var SimpleXMLElement
*/
public static $XmlContentType;

/**
* whole xml object from info xml
* @var SimpleXMLElement
*/
protected $_oXml = NULL;
protected $_xmlDefault = 'plugins/pluginmanager/xml/plugin_default.xml';
protected $_aXmlDefaultIndex;
protected $_aXmlDefaultValues;

/**
*
* @var string
*/
protected $_sXsdPath;

/**
* db-tables and table-ids used
* @var array
*/
protected $_aTables = array(
'actions' => 'idaction',
'area' => 'idarea',
'files' => 'idfile',
'framefiles' => 'idframefile',
'nav_main' => 'idnavm',
'nav_sub' => 'idnavs',
'plugins' => 'idplugin'
);

/**
* holds db object
* @var DB_ConLite
*/
protected $_oDb;
protected $_aSql = array();
protected $_iPiId = 0;
protected $_iCntQueries = 0;
protected $_iClient;
protected $_aRelations;

/**
*
* @var pimPluginCollection
*/
protected $_PimPluginCollection;

/**
*
* @var pimPluginRelationCollection
*/
protected $_PimPluginRelationCollection;
protected $_sPluginPath;

public function __construct() {
$this->_oDb = new DB_ConLite();
$this->_iClient = cRegistry::getClientId();
$this->_xmlParseIntoStruct();

$this->_PimPluginCollection = new pimPluginCollection();
$this->_PimPluginRelationCollection = new pimPluginRelationCollection();

//print_r($this->_getAttrForTag("area"));
}

public function setPluginPath($sPath) {
$this->_sPluginPath = $sPath;
}

public function getPluginPath() {
return $this->_sPluginPath;
}

/**
*
* @return boolean
*/
public function doQueries() {
if (!is_array($this->_aSql) || count($this->_aSql) <= 0) {
return TRUE;
}
$iQueries = count($this->_aSql);

if ($iQueries > 0 && is_a($this->_oDb, "DB_ConLite")) {
foreach ($this->_aSql as $sSql) {
try {
$this->_oDb->query($sSql);
} catch (Exception $exc) {
self::error($exc->getTraceAsString());
}
$this->_iCntQueries++;
}
if ($iQueries == $this->_iCntQueries) {
return TRUE;
}
}
return FALSE;
}

public function undoQueries() {
}

public function setXmlObject($oXml, $bSplit = TRUE) {
if (is_object($oXml)) {
$this->_oXml = & $oXml;
}

if ($bSplit) {
$this->_setXml();
}
}

public function setXsdFile($sFile) {
$this->_sXsdPath = $sFile;
}

/**
* Returns next id for given table
*
* @param string $sTable
* @return int the next usable table id
*/
protected function _getNextId($sTable) {
cInclude("includes", "functions.database.php");
dbUpdateSequence(cRegistry::getConfigValue("tab", "sequence"), cRegistry::getConfigValue('tab', $sTable), cRegistry::getDb());

$iNextId = $this->_oDb->nextid(cRegistry::getConfigValue('tab', $sTable));
// id must be over 10.000
if ($iNextId < 10000) {
$iNextId = 10000;
}

// added ten
$iNextId = $iNextId + 10;

// how long is the number?
$iResultStrlen = strlen($iNextId);

// removed the last number
$iNextId = substr($iNextId, 0, $iResultStrlen - 1);

return Contenido_Security::toInteger($iNextId . 0); // last number is always a zero
}

protected function _getAttrForTag($sTag) {
foreach ($this->_aXmlDefaultValues as $Key => $aValue) {
if ($aValue['tag'] === strtoupper($sTag) && $aValue['type'] === "complete") {
if (isset($aValue['attributes']) && is_array($aValue['attributes'])) {
return array_change_key_case($aValue['attributes']);
}
}
}
return FALSE;
}

protected function _getPluginSql() {
$sSqlFile = $this->_sPluginPath . static::SQL_FILE;
if (file_exists($sSqlFile) && is_readable($sSqlFile)) {
$this->_aSql = pimSqlParser::parse(file_get_contents($sSqlFile));
} else if (!is_array($this->_aSql)) {
$this->_aSql = array();
}
}

protected static function error($sMessage, $iPiId = NULL) {
if (!is_null($iPiId)) {
$oUnInstall = new pimSetupPluginUninstall();
$oUnInstall->uninstallPlugin($iPiId, '');
}
print "Error:0:" . $sMessage;
die();
}

protected function _getRelations() {
$aTmpArray = array();
$this->_PimPluginRelationCollection->setWhere('idplugin', $this->_iPiId);
$this->_PimPluginRelationCollection->query();
if ($this->_PimPluginRelationCollection->count() > 0) {
while ($oPluginRelation = $this->_PimPluginRelationCollection->next()) {
if (isset($aTmpArray[$oPluginRelation->get('type')]) && is_array($aTmpArray[$oPluginRelation->get('type')])) {
array_push($aTmpArray[$oPluginRelation->get('type')], $oPluginRelation->get('iditem'));
} else {
$aTmpArray[$oPluginRelation->get('type')] = array($oPluginRelation->get('iditem'));
}
}
$this->_aRelations = $aTmpArray;
unset($aTmpArray);
}
}

protected function _deleteRelations() {
$iDeletetRelations = $this->_PimPluginRelationCollection->deleteByWhereClause("idplugin = " . $this->_iPiId);
}

protected function _deleteRelationEntries() {
$oDb = new DB_ConLite();
foreach ($this->_aRelations as $sType => $aIds) {
$sSQL = 'DELETE FROM ' . cRegistry::getConfigValue('tab', $sType) . ' WHERE ' . $this->_aTables[$sType] . ' IN (' . implode(',', $aIds) . ')';
if ($oDb->query($sSQL) == FALSE) {
return FALSE;
}
}
unset($oDb);
return TRUE;
}

protected function _updateSortOrder() {
if(!isset($_REQUEST['new_position'])) {
return 0;
}
$oPluginColl = new pimPluginCollection();
$oPluginColl->setWhere("executionorder", (int) $_REQUEST['new_position'], ">=");
$oPluginColl->query();
if($oPluginColl->count() > 0) {
/* @var $oPlugin cApiPlugin */
while ($oPlugin = $oPluginColl->next()) {
$iOrder = $oPlugin->get("executionorder");
$oPlugin->set("executionorder", $iOrder++);
$oPlugin->store();
}
}
return (int) $_REQUEST['new_position'];
}

/**
* Set temporary xml content to static variables
*
* @param string $xml
*/
private function _setXml() {
//simplexml_tree($this->_oXml);
// General plugin informations
self::$XmlGeneral = $this->_oXml->general;

// Plugin requirements
self::$XmlRequirements = $this->_oXml->requirements;

// Plugin dependencies
self::$XmlDependencies = $this->_oXml->dependencies;

// CONTENIDO areas: *_area
self::$XmlArea = $this->_oXml->conlite->areas;

// CONTENIDO actions: *_actions
self::$XmlActions = $this->_oXml->conlite->actions;

// CONTENIDO frames: *_frame_files and *_files
self::$XmlFrames = $this->_oXml->conlite->frames;

// CONTENIDO main navigations: *_nav_main
self::$XmlNavMain = $this->_oXml->conlite->nav_main;

// CONTENIDO sub navigations: *_nav_sub
self::$XmlNavSub = $this->_oXml->conlite->nav_sub;

// CONTENIDO Content Types: *_type
self::$XmlContentType = $this->_oXml->content_types;
}

private function _xmlParseIntoStruct() {
$sData = implode("", file($this->_xmlDefault));
$oParser = xml_parser_create();
xml_parse_into_struct($oParser, $sData, $this->_aXmlDefaultValues, $this->_aXmlDefaultIndex);
xml_parser_free($oParser);
}

private function _updateSequence($table = false) {
global $db, $cfg;
if (!$table) {
$sql = "SHOW TABLES";
$db->query($sql);
while ($db->next_record()) {
dbUpdateSequence($cfg['sql']['sqlprefix'] . "_sequence", $db->f(0));
}
} else {
dbUpdateSequence($cfg['sql']['sqlprefix'] . "_sequence", $table);
}
}
}

+ 427
- 0
conlite/plugins/pluginmanager/classes/setup/class.pim.setup.plugin.install.php View File

@@ -0,0 +1,427 @@
<?php

if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}

class pimSetupPluginInstall extends pimSetupBase {

const SQL_FILE = "plugin_install.sql";

/**
*
* @var pimPlugin
*/
private $_oPlugin;
//helper arrays
private $_aAreas = array();
private $_aInstalledAreas;
private $_aInstalledNavMain;
private $_aInstalledNavSub;

public function __construct() {
parent::__construct();
$this->_initInstalledAreasArray();
}

public function installPlugin() {
if (is_null($this->_oXml)) {
cWarning(__FILE__, __LINE__, "installPlugin: No plugin xml loaded!");
return 0;
}
$this->_installCheckUuid();
$this->_installCheckRequirements();
$oPiColl = new pimPluginCollection();
$this->_oPlugin = $oPiColl->createNewItem();
if ($this->_oPlugin->isLoaded()) {
$this->_iPiId = $this->_oPlugin->get('idplugin');
$this->_insertDbEntries();
$this->_getPluginSql();
if ($this->doQueries()) {
$this->_oPlugin->set('idclient', $this->_iClient, FALSE);
$this->_oPlugin->set('name', Contenido_Security::escapeDB(self::$XmlGeneral->plugin_name));
$this->_oPlugin->set('description', Contenido_Security::escapeDB(self::$XmlGeneral->description));
$this->_oPlugin->set('author', Contenido_Security::escapeDB(self::$XmlGeneral->author));
$this->_oPlugin->set('copyright', Contenido_Security::escapeDB(self::$XmlGeneral->copyright));
$this->_oPlugin->set('mail', Contenido_Security::escapeDB(self::$XmlGeneral->mail));
$this->_oPlugin->set('website', Contenido_Security::escapeDB(self::$XmlGeneral->website));
$this->_oPlugin->set('version', Contenido_Security::escapeDB(self::$XmlGeneral->version));
$this->_oPlugin->set('folder', Contenido_Security::escapeDB(self::$XmlGeneral->plugin_foldername));
$this->_oPlugin->set('uuid', Contenido_Security::escapeDB(self::$XmlGeneral->uuid));
$this->_oPlugin->set('executionorder', $this->_updateSortOrder(), FALSE);
$this->_oPlugin->set('installed', date('Y-m-d H:i:s'), FALSE);
$this->_oPlugin->set('active', (int) self::$XmlGeneral['active'], FALSE);

if ($this->_oPlugin->store()) {
//echo "stored: ".$this->_iPiId;
return $this->_iPiId;
}
} else {
$this->_removeEmptyPlugin();
}
}
// something went wrong, return 0
return 0;
}

protected function _insertDbEntries() {
$this->_addAreas();
$this->_addActions();
$this->_addFrames();
$this->_addNavMain();
$this->_addNavSub();
}

protected function _addRelation($iIdItem, $sType) {
$oPluginRelation = $this->_PimPluginRelationCollection->createNewItem();
$oPluginRelation->set('iditem', $iIdItem, FALSE);
$oPluginRelation->set('idplugin', $this->_iPiId, FALSE);
$oPluginRelation->set('type', $sType);
$oPluginRelation->store();
unset($oPluginRelation);
}

private function _addAreas() {
$aAttributes = array();
$aDefaultAttr = array(
'menuless' => 0,
'parent' => 0,
'relevant' => 1
);
$iCountAreas = count(self::$XmlArea->area);
if ($iCountAreas > 0) {
$oAreaColl = new cApiAreaCollection();
for ($i = 0; $i < $iCountAreas; $i++) {
$sName = Contenido_Security::escapeDB(self::$XmlArea->area[$i], $this->oDb);
// build attributes
foreach (self::$XmlArea->area[$i]->attributes() as $sKey => $sValue) {
$aAttributes[$sKey] = (string) $sValue;
}
$aAttributes = array_merge($aDefaultAttr, $aAttributes);
/* @var $oArea cApiArea */
$oArea = $oAreaColl->createNewItem($this->_getNextId("area"));
$oArea->set('parent_id', Contenido_Security::escapeDB($aAttributes['parent'], $this->oDb));
$oArea->set('name', $sName);
$oArea->set('menuless', Contenido_Security::toInteger($aAttributes['menuless']));
$oArea->set('relevant', 1, FALSE);
$oArea->set('online', 1, FALSE);
if ($oArea->store()) {
$iIdItem = $oArea->get($oArea->primaryKey);
$this->_aAreas[$sName] = $iIdItem;
$this->_aInstalledAreas[] = $sName;
$this->_addRelation($iIdItem, 'area');
}
}
}
}

private function _addActions() {
$aAttributes = array();
$aDefaultAttr = array(
'relevant' => 1
);

$iCountActions = count(self::$XmlActions->action);
if ($iCountActions > 0) {
$oActionColl = new cApiActionCollection();
for ($i = 0; $i < $iCountActions; $i++) {
$sName = Contenido_Security::escapeDB(self::$XmlActions->action[$i], $this->_oDb);
foreach (self::$XmlActions->action[$i]->attributes() as $sKey => $sValue) {
$aAttributes[$sKey] = cSecurity::escapeString($sValue);
}
$aAttributes = array_merge($aDefaultAttr, array_filter($aAttributes));
if (!in_array($aAttributes['area'], $this->_aInstalledAreas)) {
parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your ConLite installation. Please contact your plugin author.', 'pluginmanager'), $aAttributes['area']));
}
/* @var $oAction cApiAction */
$oAction = $oActionColl->createNewItem($this->_getNextId("actions"));
if ($oAction->isLoaded()) {
$oAction->set("idarea", $this->_getIdForArea($aAttributes['area']));
$oAction->set("name", $sName);
$oAction->set("code", '');
$oAction->set("location", '');
$oAction->set("relevant", (int) $aAttributes['relevant']);
if ($oAction->store()) {
$this->_addRelation($oAction->get('idaction'), 'actions');
}
}
//$oAction = $oActionColl->create($aAttributes['area'], $sName, '', '', $aAttributes['relevant']);
//$this->_addRelation($oAction->get('idaction'), 'actions');
}
unset($oActionColl);
unset($oAction);
}
}

private function _addFrames() {
$aAttributes = array();
$aDefaultAttr = array();

$iCountFrames = count(self::$XmlFrames->frame);
if ($iCountFrames > 0) {
$oFrameFileColl = new cApiFrameFileCollection();
$oFileColl = new cApiFileCollection();

for ($i = 0; $i < $iCountFrames; $i++) {
// Build attributes with security checks
foreach (self::$XmlFrames->frame[$i]->attributes() as $sKey => $sValue) {
$aAttributes[$sKey] = cSecurity::escapeString($sValue);
}
$aAttributes = array_merge($aDefaultAttr, array_filter($aAttributes));

// Check for valid area
if (!array_key_exists($aAttributes['area'], $this->_aAreas) && !in_array($aAttributes['area'], $this->_aInstalledAreas)) {
parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your ConLite installation. Please contact your plugin author.', 'pluginmanager'), $aAttributes['area']));
}

/* @var $oFile cApiFile */
$oFile = $oFileColl->createNewItem($this->_getNextId("files"));
if ($oFile->isLoaded()) {
$this->_addRelation($oFile->get('idfile'), 'files');
$oFile->set("idarea", $this->_getIdForArea($aAttributes['area']));
$oFile->set("filename", $aAttributes['name']);
$oFile->set("filetype", cSecurity::escapeString($aAttributes['filetype']));

if ($oFile->store()) {
if (!empty($aAttributes['frameId'])) {
/* @var $oFrameFile cApiFrameFile */
$oFrameFile = $oFrameFileColl->createNewItem($this->_getNextId("framefiles"));
if ($oFrameFile->isLoaded()) {
$this->_addRelation($oFrameFile->get('idframefile'), 'framefiles');
$oFrameFile->set("idarea", $this->_getIdForArea($aAttributes['area']));
$oFrameFile->set("idframe", (int) $aAttributes['frameId'], FALSE);
$oFrameFile->set("idfile", (int) $oFile->get('idfile'), FALSE);
$oFrameFile->store();
}
}
}
}
}
unset($oFrameFileColl);
unset($oFileColl);
unset($oFile);
unset($oFrameFile);
}
}

private function _addNavMain() {
$aAttributes = array();

$iCountNavMain = count(self::$XmlNavMain->nav);
if ($iCountNavMain > 0) {
$oNavMainColl = new cApiNavMainCollection();

for ($i = 0; $i < $iCountNavMain; $i++) {
$sLocation = cSecurity::escapeString(self::$XmlNavMain->nav[$i]);
if (empty($sLocation)) {
parent::error(i18n('There seem to be an empty main navigation entry in plugin.xml. Please contact your plugin author.', 'pluginmanager'), $this->_iPiId);
}

// Build attributes with security checks
foreach (self::$XmlNavMain->nav[$i]->attributes() as $sKey => $sValue) {
$aAttributes[$sKey] = cSecurity::escapeString($sValue);
}

/* @var $oNavMain cApiNavMain */
$oNavMain = $oNavMainColl->createNewItem($this->_getNextId("nav_main"));
if($oNavMain->isLoaded()) {
$this->_addRelation($oNavMain->get('idnavm'), 'nav_main');
$oNavMain->set("location", $sLocation, FALSE);
$oNavMain->set("name", cSecurity::escapeString($aAttributes['name']));
$oNavMain->store();
}
}
unset($oNavMainColl);
unset($oNavMain);
}
}

private function _addNavSub() {
$aAttributes = array();
$this->_initInstalledNavMainArray();
$iCountNavSub = count(self::$XmlNavSub->nav);
if ($iCountNavSub > 0) {
$oNavSubColl = new cApiNavSubCollection();
for ($i = 0; $i < $iCountNavSub; $i++) {
$sLocation = cSecurity::escapeString(self::$XmlNavSub->nav[$i]);
if (empty($sLocation)) {
parent::error(i18n('There seem to be an empty sub navigation entry in plugin.xml. Please contact your plugin author.', 'pluginmanager'), $this->_iPiId);
}
// Build attributes with security checks
foreach (self::$XmlNavSub->nav[$i]->attributes() as $sKey => $sValue) {
$aAttributes[$sKey] = cSecurity::escapeString($sValue);
}
/* @var $oNavSub cApiNavSub */
$oNavSub = $oNavSubColl->createNewItem($this->_getNextId("nav_sub"));
if ($oNavSub->isLoaded()) {
$this->_addRelation($oNavSub->get('idnavs'), 'nav_sub');
$oNavSub->set("idnavm", $this->_getIdForNavMain($aAttributes['navm']));
$oNavSub->set("idarea", $this->_getIdForArea($aAttributes['area']));
$oNavSub->set("level", (int) $aAttributes['level']);
$oNavSub->set("location", $sLocation, FALSE);
$oNavSub->set("online", 1, FALSE);
$oNavSub->store();
}
}
unset($oNavSubColl);
unset($oNavSub);
}
}

private function _removeEmptyPlugin() {
if (empty($this->_iPiId)) {
return FALSE;
}
$this->_getRelations();
if (count($this->_aRelations) > 0) {
$this->_deleteRelationEntries();
$this->_deleteRelations();
}
$this->_PimPluginCollection->delete($this->_iPiId);
}

/**
* Check uuId: You can install a plugin only for one time
*/
private function _installCheckUuid() {
$this->_PimPluginCollection->setWhere('uuid', self::$XmlGeneral->uuid);
$this->_PimPluginCollection->query();
if ($this->_PimPluginCollection->count() > 0) {
parent::error(i18n('You can install this plugin only for one time.', 'pluginmanager'));
}
}
private function _installCheckRequirements() {

// Check min ConLite version
if (version_compare(CL_VERSION, self::$XmlRequirements->conlite->attributes()->minversion, '<')) {
parent::error(sprintf(i18n('You have to install ConLite <strong>%s</strong> or higher to install this plugin!', 'pluginmanager'), self::$XmlRequirements->conlite->attributes()->minversion));
}
// Check max ConLite version
if (self::$XmlRequirements->conlite->attributes()->maxversion) {
if (version_compare(CL_VERSION, self::$XmlRequirements->conlite->attributes()->maxversion, '>')) {
parent::error(sprintf(i18n('Your current ConLite version is to new - max ConLite version %s', 'pluginmanager'), self::$XmlRequirements->conlite->attributes()->maxversion));
}
}

// Check PHP version
if (version_compare(phpversion(), self::$XmlRequirements->attributes()->php, '<')) {
parent::error(sprintf(i18n('You have to install PHP <strong>%s</strong> or higher to install this plugin!', 'pluginmanager'), self::$XmlRequirements->attributes()->php));
}
/* @todo check and implement other requirement checks
// Check extensions
if (count(parent::$XmlRequirements->extension) != 0) {

for ($i = 0; $i < count(parent::$XmlRequirements->extension); $i++) {

if (!extension_loaded(parent::$XmlRequirements->extension[$i]->attributes()->name)) {
parent::error(sprintf(i18n('The plugin could not find the PHP extension <strong>%s</strong>. Because this is required by the plugin, it can not be installed.', 'pim'), parent::$XmlRequirements->extension[$i]->attributes()->name));
}
}
}

// Check classes
if (count(parent::$XmlRequirements->class) != 0) {

for ($i = 0; $i < count(parent::$XmlRequirements->class); $i++) {

if (!class_exists(parent::$XmlRequirements->class[$i]->attributes()->name)) {
parent::error(sprintf(i18n('The plugin could not find the class <strong>%s</strong>. Because this is required by the plugin, it can not be installed.', 'pim'), parent::$XmlRequirements->class[$i]->attributes()->name));
}
}
}

// Check functions
if (count(parent::$XmlRequirements->function) != 0) {

for ($i = 0; $i < count(parent::$XmlRequirements->function); $i++) {

if (!function_exists(parent::$XmlRequirements->function[$i]->attributes()->name)) {
parent::error(sprintf(i18n('The plugin could not find the function <strong>%s</strong>. Because this is required by the plugin, it can not be installed.', 'pim'), parent::$XmlRequirements->function[$i]->attributes()->name));
}
}
}
*
*/
}

private function _initInstalledAreasArray() {
$this->_aInstalledAreas = array();
$oAreaColl = new cApiAreaCollection();
$oAreaColl->select();
//$oAreaColl->query();
/* @var $oArea cApiArea */
while ($oArea = $oAreaColl->next()) {
$this->_aInstalledAreas[] = $oArea->get('name');
}
//print_r($this->_aInstalledAreas);
}

private function _initInstalledNavMainArray() {
$this->_aInstalledNavMain = array();
$oNavMainColl = new cApiNavMainCollection();
$oNavMainColl->select();
//$oNavMainColl->query();
/* @var $oArea cApiArea */
while ($oNavMain = $oNavMainColl->next()) {
$this->_aInstalledNavMain[$oNavMain->get('name')] = $oNavMain->get('idnavm');
}
}

private function _initInstalledNavSubArray() {
$this->_aInstalledNavSub = array();
$oNavSubColl = new cApiNavSubCollection();
$oNavMainColl->select();
//$oNavSubColl->query();
/* @var $oArea cApiArea */
while ($oNavSub = $oNavSubColl->next()) {
$this->_aInstalledNavMain[$oNavSub->get('idnavsub')] = $oNavSub->get('name');
}
}

private function _getIdForArea($sArea) {
if (array_key_exists($sArea, $this->_aAreas)) {
return $this->_aAreas[$sArea];
}

if (in_array($sArea, $this->_aInstalledAreas)) {
$oArea = new cApiArea();
$oArea->loadBy("name", $sArea);
if ($oArea->isLoaded()) {
return $oArea->get($oArea->primaryKey);
}
}
parent::error(sprintf(i18n('Defined area <strong>%s</strong> not found on your ConLite installation. Please contact your plugin author.', "pluginmanager"), $sArea), $this->_iPiId);
}
private function _getIdForNavMain($sNavMain) {
if($sNavMain == "0") {
return $sNavMain;
}
if (array_key_exists($sNavMain, $this->_aInstalledNavMain)) {
return $this->_aInstalledNavMain[$sNavMain];
}
parent::error(sprintf(i18n('Defined nav main <strong>%s</strong> not found on your ConLite installation. Please contact your plugin author.', "pluginmanager"), $sNavMain), $this->_iPiId);
}

public function __destruct() {
//echo "<pre>";
//print_r($this->_aAreas);
}

}

+ 38
- 0
conlite/plugins/pluginmanager/classes/setup/class.pim.setup.plugin.uninstall.php View File

@@ -0,0 +1,38 @@
<?php
/**
*
*/

class pimSetupPluginUninstall extends pimSetupBase {
const SQL_FILE = "plugin_uninstall.sql";

public function __construct() {
parent::__construct();
}
public function uninstallPlugin($iIdPlugin, $sDeleteSql) {
// first check if plugin is installed in db
$oPlugin = new pimPlugin($iIdPlugin);
if($oPlugin->isLoaded()) { // plugin exists in db
$this->_iPiId = (int) $iIdPlugin;
$this->_getRelations();
if(is_array($this->_aRelations) && count($this->_aRelations) > 0) {
if($this->_deleteRelationEntries()) {
$this->_deleteRelations();
} else {
return FALSE;
}
}
if($sDeleteSql == "delete") {
$this->_getPluginSql();
}
if($this->doQueries()) {
return $this->_PimPluginCollection->delete($iIdPlugin);
}
}
return FALSE;
}
}

BIN
conlite/plugins/pluginmanager/css/images/error.png View File

Before After
Width: 32  |  Height: 32  |  Size: 4.2KB

BIN
conlite/plugins/pluginmanager/css/images/info.png View File

Before After
Width: 32  |  Height: 32  |  Size: 4.3KB

BIN
conlite/plugins/pluginmanager/css/images/success.png View File

Before After
Width: 32  |  Height: 32  |  Size: 4.3KB

BIN
conlite/plugins/pluginmanager/css/images/warning.png View File

Before After
Width: 32  |  Height: 32  |  Size: 4.5KB

+ 101
- 0
conlite/plugins/pluginmanager/css/pluginmanager.css View File

@@ -0,0 +1,101 @@
/**
*
* @package pluginmanager
* @version $Rev:$
* @author Ortwin Pinke
*
* $Id:$
*/

#addplugin {
border: 1px solid #B5B5B5;
border-top: 0px;
height: 40px;
padding: 8px;
margin-left: 10px;
width: 650px;
text-align: center;
}

.plugininfo {
width: 550px;
margin-top: 10px;
}

hr {
border-color: #B5B5B5;
line-leight: 1em;