From 17fef425f3f69386f2f10835d0d12e2402430571 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Sun, 1 Mar 2009 14:31:02 +0000
Subject: [PATCH] New module: portal. allows tabbed together pages

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1349 44740490-163a-0410-bde0-09ae8108e29a
---
 .../portal/config-templates/module_portal.php | 16 +++++
 modules/portal/default-disable                |  0
 modules/portal/hooks/hook_htmlinject.php      | 41 ++++++++++++
 modules/portal/lib/Portal.php                 | 67 +++++++++++++++++++
 templates/includes/footer.php                 | 10 +++
 templates/includes/header.php                 | 38 ++++++++++-
 6 files changed, 170 insertions(+), 2 deletions(-)
 create mode 100644 modules/portal/config-templates/module_portal.php
 create mode 100644 modules/portal/default-disable
 create mode 100644 modules/portal/hooks/hook_htmlinject.php
 create mode 100644 modules/portal/lib/Portal.php

diff --git a/modules/portal/config-templates/module_portal.php b/modules/portal/config-templates/module_portal.php
new file mode 100644
index 000000000..ebcba744f
--- /dev/null
+++ b/modules/portal/config-templates/module_portal.php
@@ -0,0 +1,16 @@
+<?php
+/* 
+ * Configuration for the module portal.
+ * 
+ * $Id: $
+ */
+
+$config = array (
+
+	'pagesets' => array(
+		array('santitycheck', 'statistics'),
+	),
+	
+);
+
+?>
diff --git a/modules/portal/default-disable b/modules/portal/default-disable
new file mode 100644
index 000000000..e69de29bb
diff --git a/modules/portal/hooks/hook_htmlinject.php b/modules/portal/hooks/hook_htmlinject.php
new file mode 100644
index 000000000..507274496
--- /dev/null
+++ b/modules/portal/hooks/hook_htmlinject.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * Hook to inject HTML content into all pages...
+ *
+ * @param array &$hookinfo  hookinfo
+ */
+function portal_hook_htmlinject(&$hookinfo) {
+	assert('is_array($hookinfo)');
+	assert('array_key_exists("pre", $hookinfo)');
+	assert('array_key_exists("post", $hookinfo)');
+	assert('array_key_exists("page", $hookinfo)');
+
+	$links = array('links' => array());
+	SimpleSAML_Module::callHooks('frontpage', $links);
+
+#	echo('<pre>');	print_r($links); exit;
+
+	$portalConfig = SimpleSAML_Configuration::getConfig('module_portal.php');
+	
+
+
+	$portal = new sspmod_portal_Portal($links['links'], $portalConfig->getValue('pagesets') );
+	
+	if (!$portal->isPortalized($hookinfo['page'])) return;
+
+	#print_r($portal->getMenu($hookinfo['page'])); exit;
+
+	// Include jquery UI CSS files in header.
+	$hookinfo['jquery']['css'] = 1;
+
+	// Header
+	$hookinfo['pre'][0]  = '
+<div id="portalmenu">
+	<ul class="ui-tabs-nav">' . $portal->getMenu($hookinfo['page']) . '</ul>
+<div id="portalcontent" class="ui-tabs-panel" style="display: block;">';
+
+	// Footer
+	$hookinfo['post'][0] = '</div></div>';
+	
+}
diff --git a/modules/portal/lib/Portal.php b/modules/portal/lib/Portal.php
new file mode 100644
index 000000000..9b3dfcf41
--- /dev/null
+++ b/modules/portal/lib/Portal.php
@@ -0,0 +1,67 @@
+<?php
+
+class sspmod_portal_Portal {
+	
+	private $pages;
+	private $config;
+	
+	function __construct($pages, $config = NULL) {
+		$this->pages = $pages;
+		$this->config = $config;
+	}
+	
+	function getTabset($thispage) {
+		if (!isset($this->config)) return NULL;
+		foreach($this->config AS $set) {
+			if (in_array($thispage, $set)) {
+				return $set;
+			}
+		}
+		return NULL;
+	}
+	
+	function isPortalized($thispage) {
+		foreach($this->config AS $set) {
+			if (in_array($thispage, $set)) {
+				return TRUE;
+			}
+		}
+		return FALSE;
+	}
+	
+	function getMenu($thispage) {
+	
+		$config = SimpleSAML_Configuration::getInstance();
+		$t = new SimpleSAML_XHTML_Template($config, 'sanitycheck:check-tpl.php');
+		
+		$tabset = $this->getTabset($thispage);
+		
+		#echo($thispage);
+		#echo('<pre>'); print_r($this->pages); exit;
+		
+		$text = '<ul>';
+		foreach($this->pages AS $pageid => $page) {
+			
+			if (isset($tabset) && !in_array($pageid, $tabset, TRUE)) continue;
+			
+			#echo('This page [' . $pageid . '] is part of [' . join(',', $tabset) . ']');
+			
+			$name = 'uknown';
+			if (isset($page['text'])) $name = $page['text'];
+			if (isset($page['shorttext'])) $name = $page['shorttext'];
+			
+			if (!isset($page['href'])) {
+				$text .= '<li class="ui-tabs-selected"><a href="#">' . $t->t($name) . '</a></li>';
+			} else if($pageid === $thispage ) {
+				$text .= '<li class="ui-tabs-selected"><a href="#">' . $t->t($name) . '</a></li>';
+			} else {
+				$text .= '<li><a href="' . $page['href'] . '">' . $t->t($name) . '</a></li>';
+			}
+			
+		}
+		$text .= '</ul>';
+		return $text;
+	}
+	
+	
+}
\ No newline at end of file
diff --git a/templates/includes/footer.php b/templates/includes/footer.php
index b851679ec..329bc68f7 100644
--- a/templates/includes/footer.php
+++ b/templates/includes/footer.php
@@ -1,5 +1,15 @@
 
 
+<?php
+
+if(array_key_exists('htmlContentPost', $this->data)) {
+	foreach(array_reverse($this->data['htmlContentPost']) AS $c) {
+		echo $c;
+	}
+}
+?>
+
+
 
 		<hr />
 
diff --git a/templates/includes/header.php b/templates/includes/header.php
index 0aa15123c..15357734a 100644
--- a/templates/includes/header.php
+++ b/templates/includes/header.php
@@ -13,7 +13,28 @@ if(array_key_exists('header', $this->data)) {
 
 	<link rel="stylesheet" type="text/css" href="/<?php echo $this->data['baseurlpath']; ?>resources/default.css" />
 	<link rel="icon" type="image/icon" href="/<?php echo $this->data['baseurlpath']; ?>resources/icons/favicon.ico" />
-	<meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
+
+<?php
+
+if(array_key_exists('jquery', $this->data)) {
+	
+	#echo('<pre>'); print_r($this->data['jquery']); exit;
+	if (isset($this->data['jquery']['core']) && $this->data['jquery']['core'])
+		echo('<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery.js"></script>');
+
+	if (isset($this->data['jquery']['ui']) && $this->data['jquery']['ui'])
+		echo('<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-ui.js"></script>');
+
+	if (isset($this->data['jquery']['css']) && $this->data['jquery']['css'])
+		echo('<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 'resources/uitheme/jquery-ui-themeroller.css" />');
+	
+}
+
+?>
+
+	
+	<meta name="robots" content="noindex, nofollow" />
+	
 
 <?php	
 if(array_key_exists('head', $this->data)) {
@@ -91,6 +112,19 @@ if($onLoad !== '') {
 		echo '</div>';
 
 	}
-	
+
+
+
 	?>
 	<div id="content">
+
+
+
+<?php
+if(array_key_exists('htmlContentPre', $this->data)) {
+	foreach($this->data['htmlContentPre'] AS $c) {
+		echo $c;
+	}
+}
+
+?>
-- 
GitLab