diff --git a/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php b/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php new file mode 100644 index 0000000..77c94cc --- /dev/null +++ b/de.systopia.civiproxy/CRM/Admin/Form/Setting/ProxySettings.php @@ -0,0 +1,62 @@ +addElement('checkbox','proxy_enabled'); + $this->addElement('checkbox','image_cache_enabled'); + $this->addElement('text', 'proxy_url', ts('Proxy URL')); + + $this->addButtons(array( + array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), + array('type' => 'cancel', 'name' => ts('Cancel')), + )); + + $this->registerRule('onlyValidURL', 'callback', 'validateURL', 'CRM_Admin_Form_Setting_ProxySettings'); + } + + function addRules() { + $this->addRule('proxy_url', ts('This may only contain a valid URL'), 'onlyValidURL'); + } + + function preProcess() { + $this->assign('proxy_enabled', CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_enabled')); + $this->assign('image_cache_enabled', CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'image_cache_enabled')); + $this->setDefaults(array( + 'proxy_url' => CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_url'), + )); + } + + function postProcess() { + // process all form values and save valid settings + $values = $this->exportValues(); + + // checkboxes + CRM_Core_BAO_Setting::setItem(!empty($values['proxy_enabled']),'CiviProxy Settings', 'proxy_enabled'); + CRM_Core_BAO_Setting::setItem(!empty($values['image_cache_enabled']),'CiviProxy Settings', 'image_cache_enabled'); + + // text + if ($values['proxy_url']){ + CRM_Core_BAO_Setting::setItem($values['proxy_url'],'CiviProxy Settings', 'proxy_url'); + } + + // give feedback to user + $session = CRM_Core_Session::singleton(); + $session->setStatus(ts("Settings successfully saved"), ts('Settings'), 'success'); + $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/setting/civiproxy')); + } + + static function validateURL($value) { + 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); + } + +} diff --git a/de.systopia.civiproxy/civiproxy.php b/de.systopia.civiproxy/civiproxy.php index c237059..020521e 100644 --- a/de.systopia.civiproxy/civiproxy.php +++ b/de.systopia.civiproxy/civiproxy.php @@ -3,7 +3,7 @@ require_once 'civiproxy.civix.php'; /** - * POC email + * POC email */ function civiproxy_civicrm_alterMailParams( &$params, $context ) { foreach (array('html', 'text') as $key) { @@ -93,3 +93,21 @@ function civiproxy_civicrm_managed(&$entities) { function civiproxy_civicrm_caseTypes(&$caseTypes) { _civiproxy_civix_civicrm_caseTypes($caseTypes); } + +/** +* Implementation of hook_civicrm_alterSettingsFolders +* +* Scan for settings in custom folder and import them +* +*/ +function civiproxy_civicrm_alterSettingsFolders(&$metaDataFolders = NULL){ + static $configured = FALSE; + if ($configured) return; + $configured = TRUE; + + $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; + $extDir = $extRoot . 'settings'; + if(!in_array($extDir, $metaDataFolders)){ + $metaDataFolders[] = $extDir; + } +} diff --git a/de.systopia.civiproxy/settings/civiproxy.setting.php b/de.systopia.civiproxy/settings/civiproxy.setting.php new file mode 100644 index 0000000..3d8470a --- /dev/null +++ b/de.systopia.civiproxy/settings/civiproxy.setting.php @@ -0,0 +1,46 @@ + array( + 'group_name' => 'CiviProxy Settings', + 'group' => 'de.systopia', + 'name' => 'proxy_enabled', + 'type' => 'Integer', + 'html_type' => 'Select', + 'default' => 0, + 'add' => '4.3', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Enables or disables the proxy', + 'help_text' => 'TODO', + ), + 'image_cache_enabled' => array( + 'group_name' => 'CiviProxy Settings', + 'group' => 'de.systopia', + 'name' => 'image_cache_enabled', + 'type' => 'Integer', + 'html_type' => 'Select', + 'default' => 0, + 'add' => '4.3', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Enables or disables image cache', + 'help_text' => 'TODO', + ), + 'proxy_url' => array( + 'group_name' => 'CiviProxy Settings', + 'group' => 'de.systopia', + 'name' => 'proxy_url', + 'type' => 'String', + 'default' => "", + 'add' => '4.3', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'The URL from which the proxy will be available for requests', + '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 new file mode 100644 index 0000000..1256a3a --- /dev/null +++ b/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.hlp @@ -0,0 +1,11 @@ +{htxt id='id-proxy-enabled'} +
{ts}TODO #1{/ts}
+{/htxt} + +{htxt id='id-image-cache-enabled'} +{ts}TODO #2{/ts}
+{/htxt} + +{htxt id='id-proxy-url'} +{ts}TODO #3{/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 new file mode 100644 index 0000000..90e7cc3 --- /dev/null +++ b/de.systopia.civiproxy/templates/CRM/Admin/Form/Setting/ProxySettings.tpl @@ -0,0 +1,38 @@ + + +{literal} + + + +{/literal} diff --git a/de.systopia.civiproxy/xml/Menu/civiproxy.xml b/de.systopia.civiproxy/xml/Menu/civiproxy.xml new file mode 100644 index 0000000..441c085 --- /dev/null +++ b/de.systopia.civiproxy/xml/Menu/civiproxy.xml @@ -0,0 +1,13 @@ + +