1
0
Fork 0
Dieser Commit ist enthalten in:
Ortwin Pinke 2019-11-04 17:10:22 +01:00 committet von GitHub
Ursprung b4fc73b332
Commit 05632001a3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 359 neuen und 0 gelöschten Zeilen

19
cl_plugin.xml Normale Datei
Datei anzeigen

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<general active="1">
<plugin_name>Smarty Wrapper</plugin_name>
<plugin_foldername>smarty</plugin_foldername>
<uuid>7071C44D-3B6F-5503-8C01-38B9A6A88E71</uuid>
<description>Enhance Backend and Frontend of ConLite with Smarty Template Engine</description>
<author>Ortwin Pinke</author>
<copyright>(c) 2017 Ortwin Pinke, PHP-Backoffice.de</copyright>
<mail>info@php-backoffice.de</mail>
<website>http://php-backoffice.de</website>
<version>1.0.2</version>
<license>GNU Lesser General Public License</license>
</general>
<requirements php="5.4">
<conlite minversion="2.0.2" />
</requirements>
<conlite />
</plugin>

Datei anzeigen

@ -0,0 +1,47 @@
<?php
/**
* This file contains the backend class for smarty wrapper plugin.
*
* @package Plugin
* @subpackage SmartyWrapper
* @version $Rev: 128 $
* @since 2.0.2
* @author Ortwin Pinke <o.pinke@conlite.org>
* @copyright (c) 2018, conlite.org
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
* @link http://www.conlite.org ConLite.org
*
* $Id: class.smarty.backend.php 128 2019-07-03 11:58:28Z oldperl $
*/
/**
* @package Plugin
* @subpackage SmartyWrapper
* @author Andreas Dieter
* @copyright four for business AG <www.4fb.de>
*/
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
/**
* Wrapper class for Integration of smarty.
*
* @package Plugin
* @subpackage SmartyWrapper
*/
class cSmartyBackend extends cSmartyFrontend {
public function __construct(&$aCfg, &$aClientCfg, $bSanityCheck = false) {
parent::__construct($aCfg, $aClientCfg, false);
parent::$aDefaultPaths = array(
'template_dir' => $aCfg['path']['contenido'] . 'plugins/smarty_templates/',
'cache_dir' => $aCfg['path']['conlite_cache'],
'compile_dir' => $aCfg['path']['conlite_cache'] . 'templates_c/'
);
parent::$bSmartyInstanciated = true;
$this->resetPaths();
}
}

Datei anzeigen

@ -0,0 +1,158 @@
<?php
/**
* This file contains the frontend class for smarty wrapper plugin.
*
* @package Plugin
* @subpackage SmartyWrapper
* @version $Rev: 128 $
* @since 2.0.2
* @author Ortwin Pinke <o.pinke@conlite.org>
* @copyright (c) 2018, conlite.org
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
* @link http://www.conlite.org ConLite.org
*
* $Id: class.smarty.frontend.php 128 2019-07-03 11:58:28Z oldperl $
*/
/**
* This file contains the frontend class for smarty wrapper plugin.
*
* @package Plugin
* @subpackage SmartyWrapper
* @author Andreas Dieter
* @copyright four for business AG <www.4fb.de>
*/
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
/**
* Wrapper class for Integration of smarty.
*
* @package Plugin
* @subpackage SmartyWrapper
*/
class cSmartyFrontend {
/**
* The smarty Object
*
* @var Smarty
*/
protected static $oSmarty;
/**
* static flag to simulate singleton behaviour
*
* @var bool
*/
public static $bSmartyInstanciated = false;
/**
* static default paths
*
* @var array
*/
protected static $aDefaultPaths = array();
/**
* constructor
*
* @param array &$aCfg contenido cfg array
* @param array &$aClientCfg contenido client cfg array of the specific
* client
* @throws cException
* @throws cInvalidArgumentException if the given configurations are not an
* array
*/
public function __construct(&$aCfg, &$aClientCfg, $bSanityCheck = false) {
// check if already instanciated
if (isset(self::$bSmartyInstanciated) && self::$bSmartyInstanciated) {
throw new Exception("cSmartyFrontend class is intended to be used as singleton. Do not instanciate multiple times.");
}
if (!is_array($aCfg)) {
throw new Exception(__CLASS__ . " " . __FUNCTION__ . " Parameter 1 invalid.");
}
if (!is_array($aClientCfg)) {
throw new Exception(__CLASS__ . " " . __FUNCTION__ . " Parameter 2 invalid.");
}
self::$oSmarty = new cSmartyWrapper();
self::$aDefaultPaths = array(
'template_dir' => $aClientCfg['template']['path'],
'cache_dir' => $aClientCfg['cache']['path'] . 'templates_c',
'compile_dir' => $aClientCfg['cache']['path'] . 'templates_c'
);
// check the template directory and create new one if it not exists
if (!is_dir(self::$aDefaultPaths['compile_dir'])) {
mkdir(self::$aDefaultPaths['compile_dir'], 0777);
}
// check if folders exist and rights ok if needed
if ($bSanityCheck) {
foreach (self::$aDefaultPaths as $key => $value) {
if (!file_exists($value)) {
throw new Exception(sprintf("Class %s Error: Folder %s does not exist. Please create.", __CLASS__, $value));
}
if ($key == 'cache' || $key == 'compile_dir') {
if (!is_writable($value)) {
throw new Exception(sprintf("Class %s Error: Folder %s is not writable. Please check for sufficient rights.", __CLASS__, $value));
}
}
}
}
self::resetPaths();
self::$bSmartyInstanciated = true;
}
/**
* prevent users from cloning instance
*
* @throws cException if this function is called
*/
public function __clone() {
throw new Exception("cSmartyFrontend class is intended to be used as singleton. Do not clone.");
}
/**
* destructor
* set cSmarty::bSmartyInstanciated to false
*/
public function __destruct() {
self::$bSmartyInstanciated = false;
}
/**
* static function to provide the smart object
*
* @param boolean $bResetTemplate true if the template values shall all be
* resetted
* @throws cException if singleton has not been instantiated yet
* @return cSmartyWrapper
*/
public static function getInstance($bResetTemplate = false) {
if (!isset(self::$oSmarty)) {
// @TODO find a smart way to instanciate smarty object on demand
throw new Exception("Smarty singleton not instantiated yet.");
}
if ($bResetTemplate) {
self::$oSmarty = new cSmartyWrapper();
self::resetPaths();
}
return self::$oSmarty;
}
/**
* sets the default paths again
*/
public static function resetPaths() {
self::$oSmarty->setTemplateDir(self::$aDefaultPaths['template_dir']);
self::$oSmarty->setCacheDir(self::$aDefaultPaths['cache_dir']);
self::$oSmarty->setCompileDir(self::$aDefaultPaths['compile_dir']);
}
}
?>

Datei anzeigen

@ -0,0 +1,73 @@
<?php
/**
* This file contains the wrapper class for smarty wrapper plugin.
*
* @package Plugin
* @subpackage SmartyWrapper
* @version $Rev: 128 $
* @since 2.0.2
* @author Ortwin Pinke <o.pinke@conlite.org>
* @copyright (c) 2018, conlite.org
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
* @link http://www.conlite.org ConLite.org
*
* $Id: class.smarty.wrapper.php 128 2019-07-03 11:58:28Z oldperl $
*/
/**
* @package Plugin
* @subpackage SmartyWrapper
* @author Andreas Dieter
* @copyright four for business AG <www.4fb.de>
*/
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
class cSmartyWrapper extends Smarty {
public function fetch($template = NULL, $cache_id = NULL, $compile_id = NULL, $parent = NULL, $display = false, $merge_tpl_vars = true, $no_output_filter = false) {
/* @todo implement functionality for CL 2.0
if ($this->templateExists($template) === false) {
$moduleId = (int) cRegistry::getCurrentModuleId();
if ($moduleId > 0) {
$module = new cModuleHandler($moduleId);
$template = $module->getTemplatePath($template);
}
}
*/
return parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter);
}
public function fetchGeneral($template = NULL, $cache_id = NULL, $compile_id = NULL, $parent = NULL, $display = false, $merge_tpl_vars = true, $no_output_filter = false) {
$template = cRegistry::getFrontendPath() . 'templates/' . $template;
return parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter);
}
public function display($template = NULL, $cache_id = NULL, $compile_id = NULL, $parent = NULL) {
global $frontend_debug;
if ($frontend_debug['template_display']) {
echo("<!-- SMARTY TEMPLATE " . $template . " -->");
}
return parent::display($template, $cache_id, $compile_id, $parent);
}
public function displayGeneral($template = NULL, $cache_id = NULL, $compile_id = NULL, $parent = NULL) {
$this->fetchGeneral($template, $cache_id, $compile_id, $parent, true);
}
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) {
/* @todo implement functionality for CL 2.0
if ($this->templateExists($template_name) === false) {
$moduleId = (int) cRegistry::getCurrentModuleId();
if ($moduleId > 0) {
$module = new cModuleHandler($moduleId);
$template_name = $module->getTemplatePath($template_name);
}
}
*/
return parent::clearCache($template_name, $cache_id, $compile_id, $exp_time, $type);
}
}

Datei anzeigen

@ -0,0 +1,25 @@
<?php
/**
* This file contains the autoloader stuff for this plugin
*
* @package Plugin
* @subpackage SmartyWrapper
* @version $Rev: 128 $
* @since 2.0.2
* @author Ortwin Pinke <o.pinke@conlite.org>
* @copyright (c) 2018, conlite.org
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
* @link http://www.conlite.org ConLite.org
*
* $Id: config.autoloader.php 128 2019-07-03 11:58:28Z oldperl $
*/
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
$sAutoloadClassPath = strstr(dirname(dirname(__FILE__)), "conlite/plugins")."/classes/";
return array(
'cSmartyBackend' => $sAutoloadClassPath.'class.smarty.backend.php',
'cSmartyFrontend' => $sAutoloadClassPath.'class.smarty.frontend.php',
'cSmartyWrapper' => $sAutoloadClassPath.'class.smarty.wrapper.php'
);
?>

37
includes/config.plugin.php Normale Datei
Datei anzeigen

@ -0,0 +1,37 @@
<?php
/**
* This file is the config file for this plugin
*
* @package Plugin
* @subpackage SmartyWrapper
* @version $Rev: 128 $
* @since 2.0.2
* @author Ortwin Pinke <o.pinke@conlite.org>
* @copyright (c) 2018, conlite.org
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
* @link http://www.conlite.org ConLite.org
*
* $Id: config.plugin.php 128 2019-07-03 11:58:28Z oldperl $
*/
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
rereadClients();
$client = (isset($client)) ? $client : $load_client;
// Load smarty
if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', cRegistry::getConfigValue('path', 'conlite')
. cRegistry::getConfigValue('path', 'plugins')
. 'smarty/libs/');
}
require_once(SMARTY_DIR . 'Autoloader.php');
Smarty_Autoloader::register();
try {
new cSmartyFrontend(cRegistry::getConfig(), cRegistry::getClientConfig(cRegistry::getClientId()), true);
} catch (Exception $e) {
cWarning($e->getFile(), $e->getLine(), $e->getMessage());
}
?>