diff --git a/modules/discojuice/lib/EmbedHelper.php b/modules/discojuice/lib/EmbedHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..999f85ba09fc92a6d1522aed452eff116d5276ab --- /dev/null +++ b/modules/discojuice/lib/EmbedHelper.php @@ -0,0 +1,68 @@ +<?php + +/** + * ... + */ +class sspmod_discojuice_EmbedHelper { + + public static function head($includeJQuery = TRUE) { + + $config = SimpleSAML_Configuration::getInstance(); + $djconfig = SimpleSAML_Configuration::getOptionalConfig('disojuiceembed.php'); + + + if ($includeJQuery) { + echo '<!-- JQuery -->'; + echo '<script type="text/javascript" language="javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/jquery-1.4.3.min.js') . '"></script> + <script type="text/javascript" language="javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/jquery-ui-1.8.5.custom.min.js') . '"></script> + + <link rel="stylesheet" type="text/css" href="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/css/custom/jquery-ui-1.8.5.custom.css') . '" />'; + } + + + echo '<!-- DiscoJuice --> + <script type="text/javascript" language="javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuice.misc.js') . '"></script> + <script type="text/javascript" language="javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuice.ui.js') . '"></script> + <script type="text/javascript" language="javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuice.control.js') . '"></script> + + <script type="text/javascript" language="javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/idpdiscovery.js') . '"></script> + + <link rel="stylesheet" type="text/css" href="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/css/discojuice.css') . '" />'; + + + $options = $djconfig->getValue('discojuice.options'); + $target = $djconfig->getValue('target'); + + + echo '<script type="text/javascript">'; + echo 'var options = ' . json_encode($options) . ';' . "\n"; + echo 'var target = "' . $target . '";' . "\n\n"; + + echo 'options.countryAPI = "' . SimpleSAML_Module::getModuleURL('discojuice/country.php'). '"; ' . "\n"; + echo 'options.metadata = "' . SimpleSAML_Module::getModuleURL('discojuice/feed.php'). '"; ' . "\n"; + + echo 'options.disco = { url: "' . SimpleSAML_Module::getModuleURL('discojuice/discojuiceDiscoveryResponse.html?'). '" }; ' . "\n"; + echo 'options.discoPath = "' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/') . '"; ' . "\n"; + + + echo 'options.callback = ' . $djconfig->getValue('callback', 'null') . ';' . "\n\n"; + + + echo ' + $(document).ready(function() { + $(target).DiscoJuice(options); + }); + </script> + + '; + + + } + + + + + + +} + diff --git a/modules/discojuice/lib/Feed.php b/modules/discojuice/lib/Feed.php index 2c1edc25410602fd1c7d6588e9e254cce3c63656..e80988e862f18398ff6fe6e56ae69bce0b2f25ef 100644 --- a/modules/discojuice/lib/Feed.php +++ b/modules/discojuice/lib/Feed.php @@ -125,7 +125,7 @@ class sspmod_discojuice_Feed { private function processEntity($m) { - $data = array('entityid' => $m['entityid']); + $data = array('entityID' => $m['entityID']); $this->getCountry($data, $m); $this->getTitle($data, $m); @@ -190,14 +190,16 @@ class sspmod_discojuice_Feed { } - $c = self::countryFromURL($m['entityid']); + $c = self::countryFromURL($m['entityID']); if (!empty($c)) { $data['country'] = $c; return; } if (!empty($m['SingleSignOnService']) ) { SimpleSAML_Logger::debug('SingleSignOnService found'); + $m['metadata-set'] = 'saml20-idp-remote'; $mc = SimpleSAML_Configuration::loadFromArray($m); + $endpoint = $mc->getDefaultEndpoint('SingleSignOnService'); error_log('Endpoint: ' . var_export($endpoint, TRUE)); @@ -230,21 +232,25 @@ class sspmod_discojuice_Feed { $data['title'] = $m['name']; } else if(isset($m['name']) && array_key_exists('en', $m['name'])) { $data['title'] = $m['name']['en']; + } else if(isset($m['name']) && is_array($m['name'])) { + $data['title'] = array_pop($m['name']); } else if (isset($m['name']) && is_string($m['name'])) { $data['title'] = $m['name']; } else if (isset($m['OrganizationName']) && isset($m['OrganizationName']['en'])) { $data['title'] = $m['OrganizationName']['en']; + } else if (isset($m['OrganizationName']) && is_array($m['OrganizationName'])) { + $data['title'] = array_pop($m['OrganizationName']); } else { - $data['title'] = substr($m['entityid'], 0, 20); + $data['title'] = substr($m['entityID'], 0, 20); $data['weight'] = 9; } } protected function getOverrides(&$data, $m) { if (empty($this->overrides)) return; - if (empty($this->overrides[$m['entityid']])) return; + if (empty($this->overrides[$m['entityID']])) return; - $override = $this->overrides[$m['entityid']]; + $override = $this->overrides[$m['entityID']]; foreach($override AS $k => $v) { $data[$k] = $v; @@ -270,9 +276,9 @@ class sspmod_discojuice_Feed { } - protected function countryFromURL($entityid) { + protected function countryFromURL($entityID) { try { - $pu = parse_url($entityid, PHP_URL_HOST); + $pu = parse_url($entityID, PHP_URL_HOST); if (!empty($pu)) { $rh = strrev($pu); // error_log('Looking up TLD : ' . $rh); diff --git a/modules/discojuice/templates/central.tpl.php b/modules/discojuice/templates/central.tpl.php index 38e2aeda757e5d0d8411640791f5e75f0c46e07b..2a809af0c675c9f086a38f14733f7dfeeb943521 100644 --- a/modules/discojuice/templates/central.tpl.php +++ b/modules/discojuice/templates/central.tpl.php @@ -63,7 +63,10 @@ $options = $this->data['discojuice.options']; echo 'var options = ' . json_encode($options) . ';' . "\n\n"; echo 'options.countryAPI = "' . SimpleSAML_Module::getModuleURL('discojuice/country.php'). '"; ' . "\n"; -echo 'options.metadata = "' . SimpleSAML_Module::getModuleURL('discojuice/feed.php'). '"; ' . "\n"; + +if (empty($options['metadata'])) { + echo 'options.metadata = "' . SimpleSAML_Module::getModuleURL('discojuice/feed.php'). '"; ' . "\n"; +} echo 'options.disco = { url: "' . SimpleSAML_Module::getModuleURL('discojuice/discojuiceDiscoveryResponse.html?'). '" }; ' . "\n"; echo 'options.discoPath = "discojuice/"; ' . "\n"; diff --git a/modules/discojuice/www/discojuice/css/discojuice.css b/modules/discojuice/www/discojuice/css/discojuice.css index 51c61541326577e92d097ab7e5f1256ad166d513..84b0b53989ad32d9650e8c52779551ad41ca1d9b 100644 --- a/modules/discojuice/www/discojuice/css/discojuice.css +++ b/modules/discojuice/www/discojuice/css/discojuice.css @@ -8,7 +8,7 @@ div.discojuice { z-index: 100; margin: 0; padding: 0; - width: 320px; + width: 500px; position: absolute; top: 30px; right: 10px; @@ -112,7 +112,7 @@ div.discojuice a.textlink:hover { /* * Section for the scroller */ -div.discojuice #content { +div.discojuice .discojuice_listContent { overflow: auto; max-height: 450px; } @@ -124,9 +124,11 @@ div.discojuice div.scroller img.logo { float: right; } - +div.discojuice div.scroller a { + padding: 3px 6px; +} div.discojuice div.scroller a span { - margin: 3px; +/* margin: 3px;*/ /* display: block;*/ } div.discojuice div.scroller a span.title { @@ -147,6 +149,7 @@ div.discojuice div.scroller a span.location { div.discojuice div.scroller a span.country { font-size: 86%; color: #555; + margin-right: 7px; } div.discojuice div.scroller a div.debug { font-size: 86%; diff --git a/modules/discojuice/www/discojuice/discojuice.control.js b/modules/discojuice/www/discojuice/discojuice.control.js index f8128850c598e27ba3c3d7b63aeecbd3776f7d3c..b58f65564e44cc19ab13a96fb1071d27dc73eb69 100644 --- a/modules/discojuice/www/discojuice/discojuice.control.js +++ b/modules/discojuice/www/discojuice/discojuice.control.js @@ -22,6 +22,7 @@ DiscoJuice.Control = { "location": null, "showdistance": false, + "maxhits": 25, /* * Fetching JSON Metadata using AJAX. @@ -37,19 +38,32 @@ DiscoJuice.Control = { $.getJSON(metadataurl, function(data) { that.data = data; - that.parent.Utils.log('Successfully loaded metadata'); + that.parent.Utils.log('Successfully loaded metadata (' + data.length + ')'); that.postLoad(); }); }, "postLoad": function() { if (!this.data) return; + + // Iterate through entities, and update title from DisplayNames to support Shibboleth integration. + for(i = 0; i < this.data.length; i++) { + if (!this.data[i].title) { + if (this.data[i].DisplayNames) { + this.data[i].title = this.data[i].DisplayNames[0].value; + } + } + } + + this.readCookie(); this.prepareData(); this.discoReadSetup(); - this.showallSetup(); this.searchboxSetup(); - this.filterCountrySetup(); + if (this.parent.Utils.options.get('country', false)) { + this.filterCountrySetup(); + } + this.getCountry(); }, @@ -67,9 +81,9 @@ DiscoJuice.Control = { /* * Set weight to a specific data entry. */ - "setWeight": function(entityid, weight) { + "setWeight": function(entityID, weight) { for(i = 0; i < this.data.length; i++) { - if (this.data[i].entityid == entityid) { + if (this.data[i].entityID == entityID) { if (isNaN(this.data[i].weight)) this.data[i].weight = 0; this.data[i].weight += weight; this.parent.Utils.log('COOKIE Setting weight to ' + this.data[i].weight); @@ -77,8 +91,8 @@ DiscoJuice.Control = { } }, - "discoResponse": function(entityid) { - this.setWeight(entityid, -100); + "discoResponse": function(entityID) { + this.setWeight(entityID, -100); this.prepareData(); }, @@ -150,6 +164,12 @@ DiscoJuice.Control = { }, + "increase": function() { + + this.maxhits += 100; + this.prepareData(); + + }, "prepareData": function(showall) { @@ -158,7 +178,7 @@ DiscoJuice.Control = { this.parent.Utils.log('DiscoJuice.Control prepareData()'); var hits, i, current, search; - var maxhits = 10; + var someleft = false; var term = this.getTerm(); var categories = this.getCategories(); @@ -186,16 +206,7 @@ DiscoJuice.Control = { } else { this.ui.popup.find("p.discojuice_showall").hide(); } - if (categories) { - maxhits = 125; - } - if (showall) { - maxhits = 200; - } -// if (term) { -// maxhits = 10; -// } - + this.ui.clearItems(); hits = 0; @@ -223,8 +234,8 @@ DiscoJuice.Control = { // if (categories.type !== current.ctype && current.weight > -50) continue; // } - if (++hits > maxhits) { // && showall !== true) { - this.ui.popup.find("p.discojuice_showall").show(); + if (++hits > this.maxhits) { + someleft = true; break; } @@ -245,34 +256,25 @@ DiscoJuice.Control = { this.ui.addItem(current, countrydef, search, current.distance); - - } - if (hits < maxhits) { // && showall !== true) { -// this.ui.popup.find("p.discojuice_showall").hide(); } - this.ui.refreshData(); - - //log('Loaded ' + DiscoJuice.data.length + ' accounts to select from'); + this.ui.refreshData(someleft, this.maxhits, hits); }, - "discoWrite": function(entityid) { - - }, - "selectProvider": function(entityid) { + "selectProvider": function(entityID) { var callback; var that = this; - var mustwait = that.discoWrite(entityid); + var mustwait = that.discoWrite(entityID); if (this.parent.Utils.options.get('cookie', false)) { - this.parent.Utils.log('COOKIE write ' + entityid); - this.parent.Utils.createCookie(entityid); + this.parent.Utils.log('COOKIE write ' + entityID); + this.parent.Utils.createCookie(entityID); } var entity = null; for(i = 0; i < this.data.length; i++) { - if (this.data[i].entityid == entityid) { + if (this.data[i].entityID == entityID) { entity = this.data[i]; } } @@ -384,7 +386,9 @@ DiscoJuice.Control = { ftext += '<option value="' + key + '" >' + this.parent.Constants.Countries[key] + '</option>'; } } - ftext += '</select></p>'; + ftext += '</select>'; + ftext += ' <a class="discojuice_showall textlink" href="">show all countries</a>'; + ftext += '</p>'; this.ui.addFilter(ftext).find("select").change(function(event) { event.preventDefault(); @@ -392,8 +396,22 @@ DiscoJuice.Control = { //DiscoJuice.listResults(); that.resetTerm(); that.ui.focusSearch(); + if (that.ui.popup.find("select.discojuice_filterCountrySelect").val() !== 'all') { + that.ui.popup.find("a.discojuice_showall").show(); + } else { + that.ui.popup.find("a.discojuice_showall").hide(); + } that.prepareData(); }); + this.ui.popup.find("a.discojuice_showall").click(function(event) { + event.preventDefault(); + that.resetCategories(); + that.resetTerm(); + that.prepareData(true); + that.ui.focusSearch(); + that.ui.popup.find("a.discojuice_showall").hide(); + }); + }, "setCountry": function(country) { if (this.parent.Constants.Countries[country]) { @@ -449,17 +467,7 @@ DiscoJuice.Control = { } }, - "showallSetup": function() { - var that = this; - this.ui.popup.find("a.discojuice_showall").click(function(event) { - event.preventDefault(); - that.resetCategories(); - that.resetTerm(); - that.prepareData(true); - that.ui.focusSearch(); - }); - }, - + "resetCategories": function() { //this.ui.popup.find("select.discojuice_filterTypeSelect").val() this.ui.popup.find("select.discojuice_filterCountrySelect").val('all'); diff --git a/modules/discojuice/www/discojuice/discojuice.ui.js b/modules/discojuice/www/discojuice/discojuice.ui.js index 03b85ad8b836e48897cd49321bef1c28247173af..2b3d027928d807baa9dc3a848ea3bfcee0d7bf64 100644 --- a/modules/discojuice/www/discojuice/discojuice.ui.js +++ b/modules/discojuice/www/discojuice/discojuice.ui.js @@ -84,7 +84,7 @@ DiscoJuice.UI = { - if (countrydef || distance) { + if (countrydef || (distance != undefined)) { textLink += '<span class="location">'; if (countrydef) { @@ -94,8 +94,13 @@ DiscoJuice.UI = { } - if (distance) { - textLink += '<span class="distance">' + Math.round(distance) + ' km' + '</span>'; + if (distance != undefined) { + if (distance < 1) { + textLink += '<span class="distance">Nearby</span>'; + } else { + textLink += '<span class="distance">' + Math.round(distance) + ' km' + '</span>'; + } + } textLink += '</span>'; // clear = true; @@ -130,13 +135,14 @@ DiscoJuice.UI = { } // Wrap in A element - textLink = '<a href="" class="' + classes + '" rel="' + escape(item.entityid) + '" title="' + escape(item.title) + '">' + + textLink = '<a href="" class="' + classes + '" rel="' + escape(item.entityID) + '" title="' + escape(item.title) + '">' + textLink + '</a>'; this.resulthtml += textLink; }, - "refreshData": function() { + + "refreshData": function(showmore, show, listcount) { var that = this; this.parent.Utils.log('DiscoJuice.UI refreshData()'); @@ -147,10 +153,25 @@ DiscoJuice.UI = { $(this).click(function(event) { event.preventDefault(); overthere.hide(); - var entityid = unescape($(this).attr('rel')); - overthere.control.selectProvider(entityid); + var entityID = unescape($(this).attr('rel')); + overthere.control.selectProvider(entityID); }); }); + + if (showmore) { + var moreLink = '<a class="discojuice_showmore textlink" href="">Results limited to ' + show + ' entries – show more…</a>'; + this.popup.find("p.discojuice_moreLinkContainer").empty().append(moreLink); + this.popup.find("p.discojuice_moreLinkContainer a.discojuice_showmore").click(function(e) { + event.preventDefault(); + that.control.increase(); + }); + } else { + this.popup.find("p.discojuice_moreLinkContainer").empty(); + if (listcount > 10) { + var moreLink = '<span style="color: #888">' + listcount + ' entries listed</span>'; + this.popup.find("p.discojuice_moreLinkContainer").append(moreLink); + } + } }, "enable": function(control) { @@ -163,11 +184,11 @@ DiscoJuice.UI = { '<p class="discojuice_subtitle">' + this.parent.Utils.options.get('subtitle', 'Subtitle') + '</p>' + '</div>' + - '<div id="content" style="">' + - '<p class="moretext"></p>' + + '<div class="discojuice_listContent" style="">' + '<div class="scroller">' + '<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> Loading list of providers...</div>' + '</div>' + + '<p class="discojuice_moreLinkContainer" style="margin: 0px; padding: 4px"> </p>' + '</div>' + '<div id="search" class="" >' + @@ -191,10 +212,7 @@ DiscoJuice.UI = { '</div>' + '<div class="filters bottom">' + -// '<p id="filterCountry"></p>' + -// '<p id="filterType"></p>' + - '<p class="discojuice_showall" ><a class="discojuice_showall textlink" href="">Show all providers</a></p>' + - '<p style="margin 0px; text-align: right; color: #ccc; font-size: x-small">DiscoJuice © 2011, UNINETT</p>' + + '<p style="margin 0px; text-align: right; color: #ccc; font-size: 75%">DiscoJuice © UNINETT</p>' + '</div>' + diff --git a/modules/discojuice/www/feed-debug.php b/modules/discojuice/www/feed-debug.php index b19ef59b9e53f8c91f6791e0f0728d3a60602041..26651caf399160143654588e59fd5de0701efc95 100644 --- a/modules/discojuice/www/feed-debug.php +++ b/modules/discojuice/www/feed-debug.php @@ -15,7 +15,7 @@ header('Content-Type: text/plain; charset=utf-8'); foreach($data AS $key => $e) { - if ($e['country'] == 'ES') { + if ($e['country'] == 'NO') { print_r($e); }