diff --git a/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php b/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php index 56db32f..99d0711 100644 --- a/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php +++ b/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php @@ -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("/

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]); + } + } + } + } diff --git a/de.systopia.civiproxy/settings/civiproxy.setting.php b/de.systopia.civiproxy/settings/civiproxy.setting.php index c4fa1c6..c46f6a1 100644 --- a/de.systopia.civiproxy/settings/civiproxy.setting.php +++ b/de.systopia.civiproxy/settings/civiproxy.setting.php @@ -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', + ), ); diff --git a/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.hlp b/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.hlp index 6d3cb49..dd49f2a 100644 --- a/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.hlp +++ b/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.hlp @@ -10,3 +10,15 @@ {ts}Enter your CiviProxy's URL here{/ts}

{/htxt} + +{htxt id='id-proxy-version'} +

+ {ts}TODO #1{/ts} +

+{/htxt} + +{htxt id='id-extoptout-url'} +

+ {ts}TODO #2{/ts} +

+{/htxt} diff --git a/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.tpl b/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.tpl index 8676f83..dfd10f4 100644 --- a/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.tpl +++ b/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.tpl @@ -3,7 +3,7 @@

{ts}Core Settings{/ts}

- +
@@ -12,6 +12,23 @@ + + + + +
{$form.proxy_url.label}   {$form.proxy_url.html}
{$form.proxy_version.label}  {$form.proxy_version.html}
+
+
+ +
+

{ts}Component Settings{/ts}

+
+
+ + + + +
{$form.civimail_external_optout.label}  {$form.civimail_external_optout.html}
@@ -21,14 +38,39 @@ {literal} {/literal}