Traditionally, CMSimple(_XH) loads all plugin configuration and language files on each request, even if some of these are not used. This is a waste of resources, which can be alleviated by using a byte-code cache, but probably many shared hosters still don't offer one, and we could still save memory by not loading unnecessary files.
Until recently, I thought that it's not possible to change that without breaking almost all plugins, but it seems it can be done by using the ArrayAccess interface. The following patch serves as POC:
Code: Select all
cmsimple/classes/PluginConfig.php | 56 +++++++++++++++++++++++++++++++++++++++
cmsimple/cms.php | 17 +++---------
plugins/jquery/jquery.inc.php | 2 +-
3 files changed, 60 insertions(+), 15 deletions(-)
diff --git a/cmsimple/classes/PluginConfig.php b/cmsimple/classes/PluginConfig.php
new file mode 100644
index 0000000..0988048
--- /dev/null
+++ b/cmsimple/classes/PluginConfig.php
@@ -0,0 +1,56 @@
+<?php
+
+class XH_PluginConfig implements ArrayAccess
+{
+ private $language;
+
+ private $configs = array();
+
+ public function __construct($language = false)
+ {
+ $this->language = $language;
+ }
+
+ public function offsetExists($offset)
+ {
+ if (!isset($this->configs[$offset])) {
+ $this->loadConfig($offset);
+ }
+ return isset($configs[$offset]);
+ }
+
+ public function offsetGet($offset)
+ {
+ if (!isset($this->configs[$offset])) {
+ $this->loadConfig($offset);
+ }
+ return $this->configs[$offset];
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ if (!isset($this->configs[$offset])) {
+ $this->loadConfig($offset);
+ }
+ $this->configs[$offset] = $value;
+ }
+
+ public function offsetUnset($offset)
+ {
+ if (!isset($this->configs[$offset])) {
+ $this->loadConfig($offset);
+ }
+ unset($this->configs[$offset]);
+ }
+
+ private function loadConfig($pluginname)
+ {
+ global $pth;
+
+ pluginFiles($pluginname);
+ if ($this->language) {
+ XH_createLanguageFile($pth['file']['plugin_language']);
+ }
+ $this->configs += XH_readConfiguration(true, $this->language);
+ }
+}
diff --git a/cmsimple/cms.php b/cmsimple/cms.php
index 54f6762..e104aa5 100644
--- a/cmsimple/cms.php
+++ b/cmsimple/cms.php
@@ -275,6 +275,7 @@ require_once $pth['folder']['classes'] . 'PasswordHash.php';
require_once $pth['folder']['classes'] . 'PageDataRouter.php';
require_once $pth['folder']['classes'] . 'PageDataModel.php';
require_once $pth['folder']['classes'] . 'PageDataView.php';
+require_once $pth['folder']['classes'] . 'PluginConfig.php';
require_once $pth['folder']['classes'] . 'PluginMenu.php';
require_once $pth['folder']['plugins'] . 'utf8/utf8.php';
require_once UTF8 . '/ucfirst.php';
@@ -1110,7 +1111,7 @@ $pd_current = $pd_router->find_page($pd_s);
*
* @see $cf
*/
-$plugin_cf = array();
+$plugin_cf = new XH_PluginConfig();
/**
* The localization of the plugins.
@@ -1123,19 +1124,7 @@ $plugin_cf = array();
*
* @see $tx
*/
-$plugin_tx = array();
-
-/*
- * Include config and language files of all plugins.
- */
-foreach (XH_plugins() as $plugin) {
- pluginFiles($plugin);
- $temp = XH_readConfiguration(true, false);
- $plugin_cf += $temp;
- XH_createLanguageFile($pth['file']['plugin_language']);
- $temp = XH_readConfiguration(true, true);
- $plugin_tx += $temp;
-}
+$plugin_tx = new XH_PluginConfig(true);
/*
* Add LINK to combined plugin stylesheet.
diff --git a/plugins/jquery/jquery.inc.php b/plugins/jquery/jquery.inc.php
index 805e800..32d766c 100644
--- a/plugins/jquery/jquery.inc.php
+++ b/plugins/jquery/jquery.inc.php
@@ -27,7 +27,7 @@ if (!defined('CMSIMPLE_XH_VERSION')) {
global $hjs, $plugin_cf, $pth;
//load plugin-configuration for xh < 1.6
-require($pth['folder']['plugins'] . 'jquery/config/config.php');
+// require($pth['folder']['plugins'] . 'jquery/config/config.php');
function include_jQuery($path = '') {
global $pth, $plugin_cf, $hjs;