Skip to content
Snippets Groups Projects
Commit 16c2618c authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Update to support nonenglish titles..

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2786 44740490-163a-0410-bde0-09ae8108e29a
parent 8297519f
No related branches found
No related tags found
No related merge requests found
<?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>
';
}
}
...@@ -125,7 +125,7 @@ class sspmod_discojuice_Feed { ...@@ -125,7 +125,7 @@ class sspmod_discojuice_Feed {
private function processEntity($m) { private function processEntity($m) {
$data = array('entityid' => $m['entityid']); $data = array('entityID' => $m['entityID']);
$this->getCountry($data, $m); $this->getCountry($data, $m);
$this->getTitle($data, $m); $this->getTitle($data, $m);
...@@ -190,14 +190,16 @@ class sspmod_discojuice_Feed { ...@@ -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($c)) { $data['country'] = $c; return; }
if (!empty($m['SingleSignOnService']) ) { if (!empty($m['SingleSignOnService']) ) {
SimpleSAML_Logger::debug('SingleSignOnService found'); SimpleSAML_Logger::debug('SingleSignOnService found');
$m['metadata-set'] = 'saml20-idp-remote';
$mc = SimpleSAML_Configuration::loadFromArray($m); $mc = SimpleSAML_Configuration::loadFromArray($m);
$endpoint = $mc->getDefaultEndpoint('SingleSignOnService'); $endpoint = $mc->getDefaultEndpoint('SingleSignOnService');
error_log('Endpoint: ' . var_export($endpoint, TRUE)); error_log('Endpoint: ' . var_export($endpoint, TRUE));
...@@ -230,21 +232,25 @@ class sspmod_discojuice_Feed { ...@@ -230,21 +232,25 @@ class sspmod_discojuice_Feed {
$data['title'] = $m['name']; $data['title'] = $m['name'];
} else if(isset($m['name']) && array_key_exists('en', $m['name'])) { } else if(isset($m['name']) && array_key_exists('en', $m['name'])) {
$data['title'] = $m['name']['en']; $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'])) { } else if (isset($m['name']) && is_string($m['name'])) {
$data['title'] = $m['name']; $data['title'] = $m['name'];
} else if (isset($m['OrganizationName']) && isset($m['OrganizationName']['en'])) { } else if (isset($m['OrganizationName']) && isset($m['OrganizationName']['en'])) {
$data['title'] = $m['OrganizationName']['en']; $data['title'] = $m['OrganizationName']['en'];
} else if (isset($m['OrganizationName']) && is_array($m['OrganizationName'])) {
$data['title'] = array_pop($m['OrganizationName']);
} else { } else {
$data['title'] = substr($m['entityid'], 0, 20); $data['title'] = substr($m['entityID'], 0, 20);
$data['weight'] = 9; $data['weight'] = 9;
} }
} }
protected function getOverrides(&$data, $m) { protected function getOverrides(&$data, $m) {
if (empty($this->overrides)) return; 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) { foreach($override AS $k => $v) {
$data[$k] = $v; $data[$k] = $v;
...@@ -270,9 +276,9 @@ class sspmod_discojuice_Feed { ...@@ -270,9 +276,9 @@ class sspmod_discojuice_Feed {
} }
protected function countryFromURL($entityid) { protected function countryFromURL($entityID) {
try { try {
$pu = parse_url($entityid, PHP_URL_HOST); $pu = parse_url($entityID, PHP_URL_HOST);
if (!empty($pu)) { if (!empty($pu)) {
$rh = strrev($pu); $rh = strrev($pu);
// error_log('Looking up TLD : ' . $rh); // error_log('Looking up TLD : ' . $rh);
......
...@@ -63,7 +63,10 @@ $options = $this->data['discojuice.options']; ...@@ -63,7 +63,10 @@ $options = $this->data['discojuice.options'];
echo 'var options = ' . json_encode($options) . ';' . "\n\n"; echo 'var options = ' . json_encode($options) . ';' . "\n\n";
echo 'options.countryAPI = "' . SimpleSAML_Module::getModuleURL('discojuice/country.php'). '"; ' . "\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.disco = { url: "' . SimpleSAML_Module::getModuleURL('discojuice/discojuiceDiscoveryResponse.html?'). '" }; ' . "\n";
echo 'options.discoPath = "discojuice/"; ' . "\n"; echo 'options.discoPath = "discojuice/"; ' . "\n";
......
...@@ -8,7 +8,7 @@ div.discojuice { ...@@ -8,7 +8,7 @@ div.discojuice {
z-index: 100; z-index: 100;
margin: 0; margin: 0;
padding: 0; padding: 0;
width: 320px; width: 500px;
position: absolute; position: absolute;
top: 30px; top: 30px;
right: 10px; right: 10px;
...@@ -112,7 +112,7 @@ div.discojuice a.textlink:hover { ...@@ -112,7 +112,7 @@ div.discojuice a.textlink:hover {
/* /*
* Section for the scroller * Section for the scroller
*/ */
div.discojuice #content { div.discojuice .discojuice_listContent {
overflow: auto; overflow: auto;
max-height: 450px; max-height: 450px;
} }
...@@ -124,9 +124,11 @@ div.discojuice div.scroller img.logo { ...@@ -124,9 +124,11 @@ div.discojuice div.scroller img.logo {
float: right; float: right;
} }
div.discojuice div.scroller a {
padding: 3px 6px;
}
div.discojuice div.scroller a span { div.discojuice div.scroller a span {
margin: 3px; /* margin: 3px;*/
/* display: block;*/ /* display: block;*/
} }
div.discojuice div.scroller a span.title { div.discojuice div.scroller a span.title {
...@@ -147,6 +149,7 @@ div.discojuice div.scroller a span.location { ...@@ -147,6 +149,7 @@ div.discojuice div.scroller a span.location {
div.discojuice div.scroller a span.country { div.discojuice div.scroller a span.country {
font-size: 86%; font-size: 86%;
color: #555; color: #555;
margin-right: 7px;
} }
div.discojuice div.scroller a div.debug { div.discojuice div.scroller a div.debug {
font-size: 86%; font-size: 86%;
......
...@@ -22,6 +22,7 @@ DiscoJuice.Control = { ...@@ -22,6 +22,7 @@ DiscoJuice.Control = {
"location": null, "location": null,
"showdistance": false, "showdistance": false,
"maxhits": 25,
/* /*
* Fetching JSON Metadata using AJAX. * Fetching JSON Metadata using AJAX.
...@@ -37,19 +38,32 @@ DiscoJuice.Control = { ...@@ -37,19 +38,32 @@ DiscoJuice.Control = {
$.getJSON(metadataurl, function(data) { $.getJSON(metadataurl, function(data) {
that.data = data; that.data = data;
that.parent.Utils.log('Successfully loaded metadata'); that.parent.Utils.log('Successfully loaded metadata (' + data.length + ')');
that.postLoad(); that.postLoad();
}); });
}, },
"postLoad": function() { "postLoad": function() {
if (!this.data) return; 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.readCookie();
this.prepareData(); this.prepareData();
this.discoReadSetup(); this.discoReadSetup();
this.showallSetup();
this.searchboxSetup(); this.searchboxSetup();
this.filterCountrySetup(); if (this.parent.Utils.options.get('country', false)) {
this.filterCountrySetup();
}
this.getCountry(); this.getCountry();
}, },
...@@ -67,9 +81,9 @@ DiscoJuice.Control = { ...@@ -67,9 +81,9 @@ DiscoJuice.Control = {
/* /*
* Set weight to a specific data entry. * Set weight to a specific data entry.
*/ */
"setWeight": function(entityid, weight) { "setWeight": function(entityID, weight) {
for(i = 0; i < this.data.length; i++) { 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; if (isNaN(this.data[i].weight)) this.data[i].weight = 0;
this.data[i].weight += weight; this.data[i].weight += weight;
this.parent.Utils.log('COOKIE Setting weight to ' + this.data[i].weight); this.parent.Utils.log('COOKIE Setting weight to ' + this.data[i].weight);
...@@ -77,8 +91,8 @@ DiscoJuice.Control = { ...@@ -77,8 +91,8 @@ DiscoJuice.Control = {
} }
}, },
"discoResponse": function(entityid) { "discoResponse": function(entityID) {
this.setWeight(entityid, -100); this.setWeight(entityID, -100);
this.prepareData(); this.prepareData();
}, },
...@@ -150,6 +164,12 @@ DiscoJuice.Control = { ...@@ -150,6 +164,12 @@ DiscoJuice.Control = {
}, },
"increase": function() {
this.maxhits += 100;
this.prepareData();
},
"prepareData": function(showall) { "prepareData": function(showall) {
...@@ -158,7 +178,7 @@ DiscoJuice.Control = { ...@@ -158,7 +178,7 @@ DiscoJuice.Control = {
this.parent.Utils.log('DiscoJuice.Control prepareData()'); this.parent.Utils.log('DiscoJuice.Control prepareData()');
var hits, i, current, search; var hits, i, current, search;
var maxhits = 10; var someleft = false;
var term = this.getTerm(); var term = this.getTerm();
var categories = this.getCategories(); var categories = this.getCategories();
...@@ -186,16 +206,7 @@ DiscoJuice.Control = { ...@@ -186,16 +206,7 @@ DiscoJuice.Control = {
} else { } else {
this.ui.popup.find("p.discojuice_showall").hide(); this.ui.popup.find("p.discojuice_showall").hide();
} }
if (categories) {
maxhits = 125;
}
if (showall) {
maxhits = 200;
}
// if (term) {
// maxhits = 10;
// }
this.ui.clearItems(); this.ui.clearItems();
hits = 0; hits = 0;
...@@ -223,8 +234,8 @@ DiscoJuice.Control = { ...@@ -223,8 +234,8 @@ DiscoJuice.Control = {
// if (categories.type !== current.ctype && current.weight > -50) continue; // if (categories.type !== current.ctype && current.weight > -50) continue;
// } // }
if (++hits > maxhits) { // && showall !== true) { if (++hits > this.maxhits) {
this.ui.popup.find("p.discojuice_showall").show(); someleft = true;
break; break;
} }
...@@ -245,34 +256,25 @@ DiscoJuice.Control = { ...@@ -245,34 +256,25 @@ DiscoJuice.Control = {
this.ui.addItem(current, countrydef, search, current.distance); this.ui.addItem(current, countrydef, search, current.distance);
}
if (hits < maxhits) { // && showall !== true) {
// this.ui.popup.find("p.discojuice_showall").hide();
} }
this.ui.refreshData(); this.ui.refreshData(someleft, this.maxhits, hits);
//log('Loaded ' + DiscoJuice.data.length + ' accounts to select from');
}, },
"discoWrite": function(entityid) {
},
"selectProvider": function(entityid) { "selectProvider": function(entityID) {
var callback; var callback;
var that = this; var that = this;
var mustwait = that.discoWrite(entityid); var mustwait = that.discoWrite(entityID);
if (this.parent.Utils.options.get('cookie', false)) { if (this.parent.Utils.options.get('cookie', false)) {
this.parent.Utils.log('COOKIE write ' + entityid); this.parent.Utils.log('COOKIE write ' + entityID);
this.parent.Utils.createCookie(entityid); this.parent.Utils.createCookie(entityID);
} }
var entity = null; var entity = null;
for(i = 0; i < this.data.length; i++) { for(i = 0; i < this.data.length; i++) {
if (this.data[i].entityid == entityid) { if (this.data[i].entityID == entityID) {
entity = this.data[i]; entity = this.data[i];
} }
} }
...@@ -384,7 +386,9 @@ DiscoJuice.Control = { ...@@ -384,7 +386,9 @@ DiscoJuice.Control = {
ftext += '<option value="' + key + '" >' + this.parent.Constants.Countries[key] + '</option>'; 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) { this.ui.addFilter(ftext).find("select").change(function(event) {
event.preventDefault(); event.preventDefault();
...@@ -392,8 +396,22 @@ DiscoJuice.Control = { ...@@ -392,8 +396,22 @@ DiscoJuice.Control = {
//DiscoJuice.listResults(); //DiscoJuice.listResults();
that.resetTerm(); that.resetTerm();
that.ui.focusSearch(); 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(); 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) { "setCountry": function(country) {
if (this.parent.Constants.Countries[country]) { if (this.parent.Constants.Countries[country]) {
...@@ -449,17 +467,7 @@ DiscoJuice.Control = { ...@@ -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() { "resetCategories": function() {
//this.ui.popup.find("select.discojuice_filterTypeSelect").val() //this.ui.popup.find("select.discojuice_filterTypeSelect").val()
this.ui.popup.find("select.discojuice_filterCountrySelect").val('all'); this.ui.popup.find("select.discojuice_filterCountrySelect").val('all');
......
...@@ -84,7 +84,7 @@ DiscoJuice.UI = { ...@@ -84,7 +84,7 @@ DiscoJuice.UI = {
if (countrydef || distance) { if (countrydef || (distance != undefined)) {
textLink += '<span class="location">'; textLink += '<span class="location">';
if (countrydef) { if (countrydef) {
...@@ -94,8 +94,13 @@ DiscoJuice.UI = { ...@@ -94,8 +94,13 @@ DiscoJuice.UI = {
} }
if (distance) { if (distance != undefined) {
textLink += '<span class="distance">' + Math.round(distance) + ' km' + '</span>'; if (distance < 1) {
textLink += '<span class="distance">Nearby</span>';
} else {
textLink += '<span class="distance">' + Math.round(distance) + ' km' + '</span>';
}
} }
textLink += '</span>'; textLink += '</span>';
// clear = true; // clear = true;
...@@ -130,13 +135,14 @@ DiscoJuice.UI = { ...@@ -130,13 +135,14 @@ DiscoJuice.UI = {
} }
// Wrap in A element // 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>'; textLink + '</a>';
this.resulthtml += textLink; this.resulthtml += textLink;
}, },
"refreshData": function() {
"refreshData": function(showmore, show, listcount) {
var that = this; var that = this;
this.parent.Utils.log('DiscoJuice.UI refreshData()'); this.parent.Utils.log('DiscoJuice.UI refreshData()');
...@@ -147,10 +153,25 @@ DiscoJuice.UI = { ...@@ -147,10 +153,25 @@ DiscoJuice.UI = {
$(this).click(function(event) { $(this).click(function(event) {
event.preventDefault(); event.preventDefault();
overthere.hide(); overthere.hide();
var entityid = unescape($(this).attr('rel')); var entityID = unescape($(this).attr('rel'));
overthere.control.selectProvider(entityid); 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) { "enable": function(control) {
...@@ -163,11 +184,11 @@ DiscoJuice.UI = { ...@@ -163,11 +184,11 @@ DiscoJuice.UI = {
'<p class="discojuice_subtitle">' + this.parent.Utils.options.get('subtitle', 'Subtitle') + '</p>' + '<p class="discojuice_subtitle">' + this.parent.Utils.options.get('subtitle', 'Subtitle') + '</p>' +
'</div>' + '</div>' +
'<div id="content" style="">' + '<div class="discojuice_listContent" style="">' +
'<p class="moretext"></p>' +
'<div class="scroller">' + '<div class="scroller">' +
'<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> Loading list of providers...</div>' + '<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> Loading list of providers...</div>' +
'</div>' + '</div>' +
'<p class="discojuice_moreLinkContainer" style="margin: 0px; padding: 4px">&nbsp;</p>' +
'</div>' + '</div>' +
'<div id="search" class="" >' + '<div id="search" class="" >' +
...@@ -191,10 +212,7 @@ DiscoJuice.UI = { ...@@ -191,10 +212,7 @@ DiscoJuice.UI = {
'</div>' + '</div>' +
'<div class="filters bottom">' + '<div class="filters bottom">' +
// '<p id="filterCountry"></p>' + '<p style="margin 0px; text-align: right; color: #ccc; font-size: 75%">DiscoJuice &copy; UNINETT</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 &copy; 2011, UNINETT</p>' +
'</div>' + '</div>' +
......
...@@ -15,7 +15,7 @@ header('Content-Type: text/plain; charset=utf-8'); ...@@ -15,7 +15,7 @@ header('Content-Type: text/plain; charset=utf-8');
foreach($data AS $key => $e) { foreach($data AS $key => $e) {
if ($e['country'] == 'ES') { if ($e['country'] == 'NO') {
print_r($e); print_r($e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment