summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/module.inc.php39
-rw-r--r--inc/render.inc.php14
2 files changed, 45 insertions, 8 deletions
diff --git a/inc/module.inc.php b/inc/module.inc.php
index 597cfb57..52646983 100644
--- a/inc/module.inc.php
+++ b/inc/module.inc.php
@@ -142,13 +142,23 @@ class Module
private $activated = false;
private $dependencies = array();
private $name;
+ /**
+ * @var array assoc list of 'filename.css' => true|false (true = always load, false = only if module is main module)
+ */
+ private $css = array();
+ /**
+ * @var array assoc list of 'filename.js' => true|false (true = always load, false = only if module is main module)
+ */
+ private $scripts = array();
private function __construct($name)
{
$file = 'modules/' . $name . '/config.json';
$json = @json_decode(@file_get_contents($file), true);
- if (isset($json['dependencies']) && is_array($json['dependencies'])) {
- $this->dependencies = $json['dependencies'];
+ foreach (['dependencies', 'css', 'scripts'] as $key) {
+ if (isset($json[$key]) && is_array($json[$key])) {
+ $this->$key = $json[$key];
+ }
}
if (isset($json['category']) && is_string($json['category'])) {
$this->category = $json['category'];
@@ -251,4 +261,29 @@ class Module
return 'modules/' . $this->name;
}
+ public function getScripts($externalOnly)
+ {
+ error_log($this->getIdentifier() . ' = ' . ($externalOnly ? 'true' : 'false'));
+ if (!$externalOnly) {
+ if (!isset($this->scripts['clientscript.js']) && file_exists($this->getDir() . '/clientscript.js')) {
+ $this->scripts['clientscript.js'] = false;
+ }
+ return array_keys($this->scripts);
+ }
+ error_log('Pre: ' . implode(', ', array_keys($this->scripts)));
+ error_log('Post: ' . implode(', ', array_keys(array_filter($this->scripts))));
+ return array_keys(array_filter($this->scripts));
+ }
+
+ public function getCss($externalOnly)
+ {
+ if (!$externalOnly) {
+ if (!isset($this->css['style.css']) && file_exists($this->getDir() . '/style.css')) {
+ $this->css['style.css'] = false;
+ }
+ return array_keys($this->css);
+ }
+ return array_keys(array_filter($this->css));
+ }
+
}
diff --git a/inc/render.inc.php b/inc/render.inc.php
index 72993ab5..53e2f314 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -51,7 +51,9 @@ class Render
public static function output()
{
Header('Content-Type: text/html; charset=utf-8');
+ /* @var $modules Module[] */
$modules = array_reverse(Module::getActivated());
+ $pageModule = Page::getModule();
$title = Property::get('page-title-prefix', '');
$bgcolor = Property::get('logo-background', '');
if (!empty($bgcolor) || !empty($title)) {
@@ -79,9 +81,9 @@ class Render
';
// Include any module specific styles
foreach ($modules as $module) {
- $file = $module->getDir() . '/style.css';
- if (file_exists($file)) {
- echo '<link href="', $file, '" rel="stylesheet" media="screen">';
+ $files = $module->getCss($module != $pageModule);
+ foreach ($files as $file) {
+ echo '<link href="', $module->getDir(), '/', $file, '" rel="stylesheet" media="screen">';
}
}
echo '
@@ -109,9 +111,9 @@ class Render
<script src="script/collapse.js"></script>
';
foreach ($modules as $module) {
- $file = $module->getDir() . '/clientscript.js';
- if (file_exists($file)) {
- echo '<script src="', $file, '"></script>';
+ $files = $module->getScripts($module != $pageModule);
+ foreach ($files as $file) {
+ echo '<script src="', $module->getDir(), '/', $file, '"></script>';
}
}
echo