From 3837d5a91aa7b81d5ae5918327e4fbbdbe3dd741 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 20 Aug 2008 09:14:16 +0000
Subject: [PATCH] Added modinfo module, which lists installed modules.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@824 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/modinfo/default-enable                |  3 ++
 modules/modinfo/dictionaries/dict.php         | 23 +++++++++++++
 modules/modinfo/hooks/hook_frontpage.php      | 17 ++++++++++
 modules/modinfo/templates/default/modlist.php | 34 +++++++++++++++++++
 modules/modinfo/www/index.php                 | 19 +++++++++++
 5 files changed, 96 insertions(+)
 create mode 100644 modules/modinfo/default-enable
 create mode 100644 modules/modinfo/dictionaries/dict.php
 create mode 100644 modules/modinfo/hooks/hook_frontpage.php
 create mode 100644 modules/modinfo/templates/default/modlist.php
 create mode 100644 modules/modinfo/www/index.php

diff --git a/modules/modinfo/default-enable b/modules/modinfo/default-enable
new file mode 100644
index 000000000..25615cb47
--- /dev/null
+++ b/modules/modinfo/default-enable
@@ -0,0 +1,3 @@
+This file indicates that the default state of this module
+is enabled. To disable, create a file named disable in the
+same directory as this file.
diff --git a/modules/modinfo/dictionaries/dict.php b/modules/modinfo/dictionaries/dict.php
new file mode 100644
index 000000000..afa0006e5
--- /dev/null
+++ b/modules/modinfo/dictionaries/dict.php
@@ -0,0 +1,23 @@
+<?php
+
+$lang = array(
+	'modlist_header' => array (
+		'en' => 'Available modules',
+	),
+	'modlist_name' => array (
+		'en' => 'Name',
+	),
+	'modlist_status' => array (
+		'en' => 'Status',
+	),
+	'modlist_enabled' => array (
+		'en' => 'Enabled',
+	),
+	'modlist_disabled' => array (
+		'en' => 'Disabled',
+	),
+
+);
+
+
+?>
\ No newline at end of file
diff --git a/modules/modinfo/hooks/hook_frontpage.php b/modules/modinfo/hooks/hook_frontpage.php
new file mode 100644
index 000000000..2f8b5ccb2
--- /dev/null
+++ b/modules/modinfo/hooks/hook_frontpage.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Hook to add the modinfo module to the frontpage.
+ *
+ * @param array &$links  The links on the frontpage, split into sections.
+ */
+function modinfo_hook_frontpage(&$links) {
+	assert('is_array($links)');
+	assert('array_key_exists("links", $links)');
+
+	$links['links'][] = array(
+		'href' => SimpleSAML_Module::getModuleURL('modinfo/'),
+		'text' => '{modinfo:dict:modlist_header}',
+		);
+
+}
+?>
\ No newline at end of file
diff --git a/modules/modinfo/templates/default/modlist.php b/modules/modinfo/templates/default/modlist.php
new file mode 100644
index 000000000..09a471794
--- /dev/null
+++ b/modules/modinfo/templates/default/modlist.php
@@ -0,0 +1,34 @@
+<?php
+$this->data['header'] = $this->t('{modinfo:dict:modlist_header}');
+$this->includeAtTemplateBase('includes/header.php');
+
+#$icon_enabled  = '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" alt="' .
+#htmlspecialchars($this->t(...)" />';
+#$icon_disabled = '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" alt="disabled" />';
+
+?>
+<div id="content">
+
+<h2><?php echo($this->data['header']); ?></h2>
+
+<table>
+<tr>
+<th><?php echo($this->t('{modinfo:dict:modlist_name}')); ?></th>
+<th><?php echo($this->t('{modinfo:dict:modlist_status}')); ?></th>
+</tr>
+<?php
+foreach($this->data['modules'] as $id => $info) {
+	echo('<tr>');
+	echo('<td>' . htmlspecialchars($id) . '</td>');
+	if($info['enabled']) {
+		echo('<td><img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" alt="' .
+			htmlspecialchars($this->t('{modinfo:dict:modlist_enabled}')) . '" /></td>');
+	} else {
+		echo('<td><img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" alt="' .
+			htmlspecialchars($this->t('{modinfo:dict:modlist_disabled}')) . '" /></td>');
+	}
+	echo('</tr>');
+}
+?>
+</table>
+<?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
diff --git a/modules/modinfo/www/index.php b/modules/modinfo/www/index.php
new file mode 100644
index 000000000..1de275fd7
--- /dev/null
+++ b/modules/modinfo/www/index.php
@@ -0,0 +1,19 @@
+<?php
+
+$modules = SimpleSAML_Module::getModules();
+sort($modules);
+
+$modinfo = array();
+
+foreach($modules as $m) {
+	$modinfo[$m] = array(
+		'enabled' => SimpleSAML_Module::isModuleEnabled($m),
+		);
+}
+
+$config = SimpleSAML_Configuration::getInstance();
+$t = new SimpleSAML_XHTML_Template($config, 'modinfo:modlist.php');
+$t->data['modules'] = $modinfo;
+$t->show();
+
+?>
\ No newline at end of file
-- 
GitLab