Skip to content

Commit

Permalink
Fixes #5912 Removing UI code + refactor out the un-needed parameter t…
Browse files Browse the repository at this point in the history
…o function `$parseToHost`
  • Loading branch information
mattab committed Aug 4, 2014
1 parent 32ea4dd commit 00ab57f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 69 deletions.
20 changes: 11 additions & 9 deletions core/Url.php
Expand Up @@ -552,7 +552,15 @@ public static function isLocalUrl($url)

public static function getTrustedHostsFromConfig()
{
return self::getHostsFromConfig('General', 'trusted_hosts');
$hosts = self::getHostsFromConfig('General', 'trusted_hosts');

// Case user wrote in the config, http://example.com/test instead of example.com
foreach ($hosts as &$host) {
if (UrlHelper::isLookLikeUrl($host)) {
$host = parse_url($host, PHP_URL_HOST);
}
}
return $hosts;
}

public static function getTrustedHosts()
Expand All @@ -562,7 +570,7 @@ public static function getTrustedHosts()

public static function getCorsHostsFromConfig()
{
return self::getHostsFromConfig('General', 'cors_hosts', false);
return self::getHostsFromConfig('General', 'cors_hosts');
}

/**
Expand All @@ -576,7 +584,7 @@ public static function getHostSanitized($host)
return IP::sanitizeIp($host);
}

protected static function getHostsFromConfig($domain, $key, $parseToHost = true)
protected static function getHostsFromConfig($domain, $key)
{
$config = @Config::getInstance()->$domain;

Expand All @@ -588,12 +596,6 @@ protected static function getHostsFromConfig($domain, $key, $parseToHost = true)
if (!is_array($hosts)) {
return array();
}
foreach ($hosts as &$host) {
// Case user wrote in the config, http://example.com/test instead of example.com
if ($parseToHost && UrlHelper::isLookLikeUrl($host)) {
$host = parse_url($host, PHP_URL_HOST);
}
}
return $hosts;
}
}
1 change: 0 additions & 1 deletion lang/en.json
Expand Up @@ -167,7 +167,6 @@
"TrackingCode": "Tracking Code",
"TrustedHostConfirm": "Are you sure you want to change the trusted Piwik hostname?",
"TrustedHostSettings": "Trusted Piwik Hostname",
"CORSSettings": "Cross-origin resource sharing hostnames",
"UpdateSettings": "Update settings",
"UseCustomLogo": "Use a custom logo",
"ValidPiwikHostname": "Valid Piwik Hostname",
Expand Down
7 changes: 0 additions & 7 deletions plugins/CoreAdminHome/Controller.php
Expand Up @@ -51,7 +51,6 @@ public function generalSettings()
$this->handleGeneralSettingsAdmin($view);

$view->trustedHosts = Url::getTrustedHostsFromConfig();
$view->corsHosts = Url::getCorsHostsFromConfig();

$logo = new CustomLogo();
$view->branding = array('use_custom_logo' => $logo->isEnabled());
Expand Down Expand Up @@ -315,12 +314,6 @@ private function saveGeneralSettings()
Url::saveTrustedHostnameInConfig($trustedHosts);
}

// update cors host settings
$corsHosts = Common::getRequestVar('corsHosts', false, 'json');
if ($corsHosts !== false) {
Url::saveCORSHostnameInConfig($corsHosts);
}

Config::getInstance()->forceSave();

$pluginUpdateCommunication = new UpdateCommunication();
Expand Down
23 changes: 1 addition & 22 deletions plugins/CoreAdminHome/javascripts/generalSettings.js
Expand Up @@ -16,11 +16,6 @@ function sendGeneralSettingsAJAX() {
trustedHosts.push($(this).val());
});

var corsHosts = [];
$('input[name=cors_host]').each(function () {
corsHosts.push($(this).val());
});

var ajaxHandler = new ajaxHelper();
ajaxHandler.setLoadingElement();
ajaxHandler.addParams({
Expand All @@ -37,8 +32,7 @@ function sendGeneralSettingsAJAX() {
mailPassword: $('#mailPassword').val(),
mailEncryption: $('#mailEncryption').val(),
useCustomLogo: isCustomLogoEnabled(),
trustedHosts: JSON.stringify(trustedHosts),
corsHosts: JSON.stringify(corsHosts)
trustedHosts: JSON.stringify(trustedHosts)
}, 'POST');
ajaxHandler.addParams({
module: 'CoreAdminHome',
Expand Down Expand Up @@ -153,19 +147,4 @@ $(document).ready(function () {
return false;
});

// cors hosts event handling
var corsHostSettings = $('#corsSettings');
corsHostSettings.on('click', '.remove-cors-host', function (e) {
e.preventDefault();
$(this).parent('li').remove();
return false;
});
corsHostSettings.find('.add-cors-host').click(function (e) {
e.preventDefault();

// append new row to the table
corsHostSettings.find('ul').append($("#add-cors-host-template").html());
// corsHostSettings.find('li:last input').val('');
return false;
});
});
30 changes: 0 additions & 30 deletions plugins/CoreAdminHome/templates/generalSettings.twig
Expand Up @@ -319,36 +319,6 @@
{% endif %}
</div>

<h2 id="corsSection">{{ 'CoreAdminHome_CORSSettings'|translate }}</h2>
<div id='corsSettings'>

{% if not isGeneralSettingsAdminEnabled %}
{{ 'CoreAdminHome_PiwikIsInstalledAt'|translate }}: {{ corsHosts|join(", ") }}
{% else %}
<script type="template/javascript" id="add-cors-host-template">
<li>
<input name="cors_host" type="text" value=""/>
<a href="#" class="remove-cors-host" title="{{ 'General_Delete'|translate }}">
<img alt="{{ 'General_Delete'|translate }}" src="plugins/Morpheus/images/ico_delete.png" />
</a>
</li>
</script>
<ul>
{% for hostIdx, host in corsHosts %}
<li>
<input name="cors_host" type="text" value="{{ host }}"/>
<a href="#" class="remove-cors-host" title="{{ 'General_Delete'|translate }}">
<img alt="{{ 'General_Delete'|translate }}" src="plugins/Morpheus/images/ico_delete.png" />
</a>
</li>
{% endfor %}
</ul>
<div class="add-cors-host-container">
<a href="#" class="add-cors-host"><em>{{ 'General_Add'|translate }}</em></a>
</div>
{% endif %}
</div>

<input type="submit" value="{{ 'General_Save'|translate }}" id="generalSettingsSubmit" class="submit"/>
<br/>
<br/>
Expand Down

0 comments on commit 00ab57f

Please sign in to comment.