added: more options, better parameter handling, fancier settings page
This commit is contained in:
parent
72ef84fbda
commit
358ff46c98
|
|
@ -13,7 +13,10 @@ class CRM_Admin_Form_Setting_ProxySettings extends CRM_Admin_Form_Setting
|
|||
|
||||
// add all required elements
|
||||
$this->addElement('checkbox','proxy_enabled');
|
||||
$this->addElement('text', 'proxy_url', ts('Proxy URL'));
|
||||
$this->addElement('text', 'proxy_url', ts('Proxy URL'), array('disabled' => 'disabled'));
|
||||
$this->addElement('static', 'proxy_version', ts('Proxy version'));
|
||||
|
||||
$this->addElement('text', 'civimail_external_optout', ts('CiviMail: External out-out page'), array('disabled' => 'disabled'));
|
||||
|
||||
$this->addButtons(array(
|
||||
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE),
|
||||
|
|
@ -25,12 +28,30 @@ class CRM_Admin_Form_Setting_ProxySettings extends CRM_Admin_Form_Setting
|
|||
|
||||
function addRules() {
|
||||
$this->addRule('proxy_url', ts('This may only contain a valid URL'), 'onlyValidURL');
|
||||
$this->addRule('civimail_external_optout', ts('This may only contain a valid URL'), 'onlyValidURL');
|
||||
}
|
||||
|
||||
function preProcess() {
|
||||
$this->assign('proxy_enabled', CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_enabled'));
|
||||
$proxyUrl = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_url');
|
||||
$proxyVersion = "-";
|
||||
|
||||
if($proxyUrl) {
|
||||
// try to get the current proxy version
|
||||
$response = $this->requestProxyVersion($proxyUrl);
|
||||
if ($response['is_error']) {
|
||||
$proxyVersion = $response['message'];
|
||||
CRM_Core_BAO_Setting::setItem(NULL,'CiviProxy Settings', 'proxy_version');
|
||||
}else{
|
||||
$proxyVersion = $response['version'];
|
||||
CRM_Core_BAO_Setting::setItem($proxyVersion,'CiviProxy Settings', 'proxy_version');
|
||||
}
|
||||
}
|
||||
|
||||
$this->setDefaults(array(
|
||||
'proxy_url' => CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_url'),
|
||||
'proxy_url' => $proxyUrl,
|
||||
'proxy_version' => $proxyVersion, // watch out, this might contain an error message
|
||||
'civimail_external_optout' => CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'civimail_extoptout')
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -42,9 +63,12 @@ class CRM_Admin_Form_Setting_ProxySettings extends CRM_Admin_Form_Setting
|
|||
CRM_Core_BAO_Setting::setItem(!empty($values['proxy_enabled']),'CiviProxy Settings', 'proxy_enabled');
|
||||
|
||||
// text
|
||||
if ($values['proxy_url']){
|
||||
if (isset($values['proxy_url'])) {
|
||||
CRM_Core_BAO_Setting::setItem($values['proxy_url'],'CiviProxy Settings', 'proxy_url');
|
||||
}
|
||||
if (isset($values['civimail_external_optout'])) {
|
||||
CRM_Core_BAO_Setting::setItem($values['civimail_external_optout'],'CiviProxy Settings', 'civimail_extoptout');
|
||||
}
|
||||
|
||||
// give feedback to user
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
|
@ -56,4 +80,25 @@ class CRM_Admin_Form_Setting_ProxySettings extends CRM_Admin_Form_Setting
|
|||
return preg_match("/^(http(s?):\/\/)?(((www\.)?+[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,6})+)|(localhost)|(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b))(:[0-9]{1,5})?(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/",$value);
|
||||
}
|
||||
|
||||
/* Performs an http request to the specified url and tries
|
||||
* to parse the response in order to get the current proxy
|
||||
* version
|
||||
*
|
||||
* @param $url url of the proxy to use
|
||||
* @return array(int is_error, [string message || string version])
|
||||
*/
|
||||
function requestProxyVersion($url) {
|
||||
$response = @file_get_contents($url);
|
||||
if($response === FALSE) {
|
||||
return array('is_error' => 1, 'message' => sprintf(ts('Error: cannot access "%s"'), $url));
|
||||
}else{
|
||||
$result = preg_match("/<p id=\"version\">CiviProxy Version ([0-9]+\.[0-9]+|[0-9]+\.[0-9]+\.[0-9]+)<\/p>/", $response, $output_array);
|
||||
if ($result === FALSE || $result === 0){
|
||||
return array('is_error' => 1, 'message' => sprintf(ts('Error: failed to parse version information'), $url));
|
||||
}else{
|
||||
return array('is_error' => 0, 'version' => $output_array[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,4 +30,16 @@ return array(
|
|||
'description' => 'The URL from which the proxy will be available for requests',
|
||||
'help_text' => 'TODO',
|
||||
),
|
||||
'proxy_version' => array(
|
||||
'group_name' => 'CiviProxy Settings',
|
||||
'group' => 'de.systopia',
|
||||
'name' => 'proxy_version',
|
||||
'type' => 'String',
|
||||
'default' => "",
|
||||
'add' => '4.3',
|
||||
'is_domain' => 1,
|
||||
'is_contact' => 0,
|
||||
'description' => 'The version of the currently selected proxy',
|
||||
'help_text' => 'TODO',
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,3 +10,15 @@
|
|||
{ts}Enter your CiviProxy's URL here{/ts}
|
||||
</p>
|
||||
{/htxt}
|
||||
|
||||
{htxt id='id-proxy-version'}
|
||||
<p>
|
||||
{ts}TODO #1{/ts}
|
||||
</p>
|
||||
{/htxt}
|
||||
|
||||
{htxt id='id-extoptout-url'}
|
||||
<p>
|
||||
{ts}TODO #2{/ts}
|
||||
</p>
|
||||
{/htxt}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<h3>{ts}Core Settings{/ts}</h3>
|
||||
<div>
|
||||
<div>
|
||||
<table id="core_settings">
|
||||
<table id="core_settings" class="no-border">
|
||||
<tr>
|
||||
<td class="label"><label for="proxy_enabled"> {ts}Enable proxy{/ts} <a onclick='CRM.help("{ts}Enable Proxy{/ts}", {literal}{"id":"id-proxy-enabled","file":"CRM\/Admin\/Form\/Setting\/ProxySettings"}{/literal}); return false;' href="#" title="{ts}Help{/ts}" class="helpicon"> </a></label></td>
|
||||
<td><input value="1" type="checkbox" id="proxy_enabled" name="proxy_enabled" {if $proxy_enabled}checked="checked"{/if} class="form-checkbox"/></td>
|
||||
|
|
@ -12,6 +12,23 @@
|
|||
<td class="label">{$form.proxy_url.label} <a onclick='CRM.help("{ts}Proxy URL{/ts}", {literal}{"id":"id-proxy-url","file":"CRM\/Admin\/Form\/Setting\/ProxySettings"}{/literal}); return false;' href="#" title="{ts}Help{/ts}" class="helpicon"> </a></td>
|
||||
<td>{$form.proxy_url.html}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">{$form.proxy_version.label} <a onclick='CRM.help("{ts}Proxy Version{/ts}", {literal}{"id":"id-proxy-version","file":"CRM\/Admin\/Form\/Setting\/ProxySettings"}{/literal}); return false;' href="#" title="{ts}Help{/ts}" class="helpicon"> </a></td>
|
||||
<td>{$form.proxy_version.html}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{ts}Component Settings{/ts}</h3>
|
||||
<div>
|
||||
<div>
|
||||
<table id="component_settings" class="no-border">
|
||||
<tr>
|
||||
<td class="label">{$form.civimail_external_optout.label} <a onclick='CRM.help("{ts}CiviMail: External out-out page{/ts}", {literal}{"id":"id-extoptout-url","file":"CRM\/Admin\/Form\/Setting\/ProxySettings"}{/literal}); return false;' href="#" title="{ts}Help{/ts}" class="helpicon"> </a></td>
|
||||
<td>{$form.civimail_external_optout.html}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -21,14 +38,39 @@
|
|||
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
function enableInput() {
|
||||
cj('#proxy_url').attr('disabled',!this.checked);
|
||||
cj('#civimail_external_optout').attr('disabled', !this.checked);
|
||||
}
|
||||
|
||||
function enableInputGlobal() {
|
||||
var is_enabled = cj('#proxy_enabled').attr('checked') == 'checked';
|
||||
cj('#proxy_url').attr('disabled', !is_enabled);
|
||||
cj('#civimail_external_optout').attr('disabled', !is_enabled);
|
||||
}
|
||||
|
||||
(function(cj) {
|
||||
cj('#proxy_enabled').click(enableInput);
|
||||
enableInputGlobal();
|
||||
|
||||
})(cj);
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
#proxy_url {
|
||||
width: 300px;
|
||||
#proxy_url, #civimail_external_optout {
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
.no-border,
|
||||
.no-border tr,
|
||||
.no-border tbody td,
|
||||
.no-border thead th,
|
||||
.no-border tfoot th {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.label {
|
||||
min-width: 200px;
|
||||
}
|
||||
</style>
|
||||
{/literal}
|
||||
|
|
|
|||
Loading…
Reference in New Issue