diff options
author | Simon Rettberg | 2016-05-18 18:04:56 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-18 18:04:56 +0200 |
commit | 2e18b36a287ad9b25619f9e2a073dcedf6d620ee (patch) | |
tree | 96d802fdc1c21ee9aa9b4d89a6611db7d8502433 /inc | |
parent | Modularized baseconfig fetching (api) (diff) | |
download | slx-admin-2e18b36a287ad9b25619f9e2a073dcedf6d620ee.tar.gz slx-admin-2e18b36a287ad9b25619f9e2a073dcedf6d620ee.tar.xz slx-admin-2e18b36a287ad9b25619f9e2a073dcedf6d620ee.zip |
MORE WMORK
Diffstat (limited to 'inc')
-rw-r--r-- | inc/dictionary.inc.php | 7 | ||||
-rw-r--r-- | inc/message.inc.php | 85 | ||||
-rw-r--r-- | inc/module.inc.php | 21 | ||||
-rw-r--r-- | inc/property.inc.php | 6 | ||||
-rw-r--r-- | inc/render.inc.php | 39 | ||||
-rw-r--r-- | inc/user.inc.php | 2 |
6 files changed, 116 insertions, 44 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index 0dafe9d9..5679c52d 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -90,12 +90,9 @@ class Dictionary return self::translateFileModule('main', 'global-tags', $tag); } - public static function getMessage($id) + public static function getMessage($module, $id) { - if (!preg_match('/^(\w+)\.(.+)$/', $id, $out)) { - return 'Invalid Message ID format: ' . $id; - } - $string = self::translateFileModule($out[1], 'messages', $out[2]); + $string = self::translateFileModule($module, 'messages', $id); if ($string === false) { return "($id) ({{0}}, {{1}}, {{2}}, {{3}})"; } diff --git a/inc/message.inc.php b/inc/message.inc.php index 15e89041..9197e4c2 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -13,7 +13,7 @@ class Message */ public static function addError($id) { - self::add('error', $id, func_get_args()); + self::add('danger', $id, func_get_args()); } public static function addWarning($id) @@ -40,10 +40,35 @@ class Message if (strstr($id, '.') === false) { $id = Page::getModule()->getIdentifier() . '.' . $id; } + if (count($params) > 1 && $params[1] === true) { + $params = array_slice($params, 2); + $linkModule = true; + } else { + $params = array_slice($params, 1); + $linkModule = false; + } + switch ($type) { + case 'danger': + $icon = 'exclamation-sign'; + break; + case 'warning': + $icon = 'warning'; + break; + case 'info': + $icon = 'info-sign'; + break; + case 'success': + $icon = 'ok'; + break; + default: + $icon = ''; + } self::$list[] = array( 'type' => $type, + 'icon' => $icon, 'id' => $id, - 'params' => array_slice($params, 1) + 'params' => $params, + 'link' => $linkModule ); if (self::$flushed) self::renderList(); } @@ -59,25 +84,36 @@ class Message if (empty(self::$list)) return; // Ajax - if (AJAX) { - foreach (self::$list as $item) { - $message = Dictionary::getMessage($item['id']); - foreach ($item['params'] as $index => $text) { - $message = str_replace('{{' . $index . '}}', '<b>' . htmlspecialchars($text) . '</b>', $message); - } - echo Render::parse('messagebox-' . $item['type'], array('message' => $message), 'main'); - } - self::$list = array(); - return; - } - // Non-Ajax + $mangled = array(); foreach (self::$list as $item) { - $message = Dictionary::getMessage($item['id']); + if (!preg_match('/^(\w+)\.(.+)$/', $item['id'], $out)) { + $message = 'Invalid Message ID format: ' . $item['id']; + } else { + $message = Dictionary::getMessage($out[1], $out[2]); + } foreach ($item['params'] as $index => $text) { $message = str_replace('{{' . $index . '}}', '<b>' . htmlspecialchars($text) . '</b>', $message); } - Render::addTemplate('messagebox-' . $item['type'], array('message' => $message), 'main'); - self::$alreadyDisplayed[] = $item; + if ($item['link'] && isset($out[1])) { + $item['link'] = $out[1]; + } + $mangled[] = array( + 'type' => $item['type'], + 'icon' => $item['icon'], + 'message' => $message, + 'link' => $item['link'] + ); + } + if (AJAX) { + foreach ($mangled as $entry) { + echo Render::parse('messagebox', $entry, 'main'); + } + } else { + // Non-Ajax + foreach ($mangled as $entry) { + Render::addTemplate('messagebox', $entry, 'main'); + } + self::$alreadyDisplayed = array_merge(self::$alreadyDisplayed, self::$list); } self::$list = array(); } @@ -90,7 +126,11 @@ class Message { $return = ''; foreach (self::$list as $item) { - $message = Dictionary::getMessage($item['id']); + if (!preg_match('/^(\w+)\.(.+)$/', $item['id'], $out)) { + $message = 'Invalid Message ID format: ' . $item['id']; + } else { + $message = Dictionary::getMessage($out[1], $out[2]); + } foreach ($item['params'] as $index => $text) { $message = str_replace('{{' . $index . '}}', $text, $message); } @@ -110,7 +150,11 @@ class Message $messages = is_array($_REQUEST['message']) ? $_REQUEST['message'] : array($_REQUEST['message']); foreach ($messages as $message) { $data = explode('|', $message); - if (count($data) < 2 || !preg_match('/^(error|warning|info|success)$/', $data[0])) continue; + if (substr($data[0], -1) === '@') { + $data[0] = substr($data[0], 0, -1); + array_splice($data, 1, 0, true); + } + if (count($data) < 2 || !preg_match('/^(danger|warning|info|success)$/', $data[0])) continue; self::add($data[0], $data[1], array_slice($data, 1)); } } @@ -123,6 +167,9 @@ class Message { $parts = array(); foreach (array_merge(self::$list, self::$alreadyDisplayed) as $item) { + if (isset($item['link']) && $item['link']) { + $item['type'] .= '@'; + } $str = 'message[]=' . urlencode($item['type'] . '|' .$item['id']); if (!empty($item['params'])) { $str .= '|' . urlencode(implode('|', $item['params'])); diff --git a/inc/module.inc.php b/inc/module.inc.php index 246505b5..13d9c1e4 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -22,8 +22,9 @@ class Module /** * Check whether given module is available, that is, all dependencies are - * met. If the module is available, it will be activated, so all it's classes - * are available through the auto-loader. + * met. If the module is available, it will be activated, so all its classes + * are available through the auto-loader, and any js or css is added to the + * final page output. * * @param string $moduleId module to check * @return bool true if module is available and activated @@ -88,6 +89,20 @@ class Module return self::$modules; } + /** + * @return \Module[] List of modules that have been activated + */ + public static function getActivated() + { + $ret = array(); + foreach (self::$modules as $module) { + if ($module->activated) { + $ret[] = $module; + } + } + return $ret; + } + public static function init() { if (self::$modules !== false) @@ -97,7 +112,7 @@ class Module return; self::$modules = array(); while (($dir = readdir($dh)) !== false) { - if (empty($dir) || preg_match('/[^a-zA-Z0-9]/', $dir)) + if (empty($dir) || preg_match('/[^a-zA-Z0-9_]/', $dir)) continue; if (!is_file('modules/' . $dir . '/config.json')) continue; diff --git a/inc/property.inc.php b/inc/property.inc.php index 13e3c66d..eae5033c 100644 --- a/inc/property.inc.php +++ b/inc/property.inc.php @@ -185,4 +185,10 @@ class Property return self::get('password-type', 'password'); } + + public static function getIpxeDefault() + { + return self::get('default-ipxe'); + } + } diff --git a/inc/render.inc.php b/inc/render.inc.php index 5fc5be92..b422d7f9 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -46,9 +46,8 @@ class Render public static function output() { Header('Content-Type: text/html; charset=utf-8'); - $zip = isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); - if ($zip) - ob_start(); + $modules = Module::getActivated(); + ob_start('ob_gzhandler'); echo '<!DOCTYPE html> <html> @@ -59,9 +58,16 @@ class Render <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="style/bootstrap.min.css" rel="stylesheet" media="screen"> - <link href="style/bootstrap-tagsinput.css" rel="stylesheet" media="screen"> + '; + // 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">'; + } + } + echo ' <link href="style/default.css" rel="stylesheet" media="screen"> - <script type="text/javascript"> var TOKEN = "' . Session::get('token') . '"; </script> @@ -80,20 +86,21 @@ class Render <script src="script/jquery.js"></script> <script src="script/bootstrap.min.js"></script> <script src="script/taskmanager.js"></script> - ', + <script src="script/fileselect.js"></script> + '; + foreach ($modules as $module) { + $file = $module->getDir() . '/clientscript.js'; + if (file_exists($file)) { + echo '<script src="', $file, '"></script>'; + } + } + echo self::$footer , '</body> </html>' ; - if ($zip) { - Header('Content-Encoding: gzip'); - ob_implicit_flush(false); - $gzip_contents = ob_get_contents(); - ob_end_clean(); - echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; - echo substr(gzcompress($gzip_contents, 5), 0, -4); - } + ob_end_flush(); } /** @@ -127,7 +134,7 @@ class Render */ public static function addScriptTop($file) { - self::addHeader('<script src="script/' . $file . '.js"></script>'); + trigger_error('Ignoring addScriptTop for ' . $file . ': Deprecated, use module-specific clientscript.js', E_USER_WARNING); } /** @@ -137,7 +144,7 @@ class Render */ public static function addScriptBottom($file) { - self::addFooter('<script src="script/' . $file . '.js"></script>'); + trigger_error('Ignoring addScriptBottom for ' . $file . ': Deprecated, use module-specific clientscript.js', E_USER_WARNING); } /** diff --git a/inc/user.inc.php b/inc/user.inc.php index d3cdc65a..595f4745 100644 --- a/inc/user.inc.php +++ b/inc/user.inc.php @@ -30,7 +30,7 @@ class User { if (!self::isLoggedIn()) return false; - return (self::$user['permissions'] & Permission::get($permission)) != 0; + return (self::$user['permissions'] & (Permission::get($permission) | Permission::get('superadmin'))) != 0; } public static function load() |