(NFC) (dev/core#878) Simplify copyright header (CRM/*)
[civicrm-core.git] / CRM / Admin / Form / Setting / Url.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for Site Url.
20 */
21 class CRM_Admin_Form_Setting_Url extends CRM_Admin_Form_Setting {
22 protected $_settings = [
23 'disable_core_css' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
24 'userFrameworkResourceURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
25 'imageUploadURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
26 'customCSSURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
27 'extensionsURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
28 ];
29
30 /**
31 * Build the form object.
32 */
33 public function buildQuickForm() {
34 CRM_Utils_System::setTitle(ts('Settings - Resource URLs'));
35 $settingFields = civicrm_api('setting', 'getfields', [
36 'version' => 3,
37 ]);
38
39 $this->addYesNo('enableSSL', ts('Force Secure URLs (SSL)'));
40 $this->addYesNo('verifySSL', ts('Verify SSL Certs'));
41 // FIXME: verifySSL should use $_settings instead of manually adding fields
42 $this->assign('verifySSL_description', $settingFields['values']['verifySSL']['description']);
43
44 $this->addFormRule(['CRM_Admin_Form_Setting_Url', 'formRule']);
45
46 parent::buildQuickForm();
47 }
48
49 /**
50 * @param $fields
51 *
52 * @return array|bool
53 */
54 public static function formRule($fields) {
55 if (isset($fields['enableSSL']) &&
56 $fields['enableSSL']
57 ) {
58 $config = CRM_Core_Config::singleton();
59 $url = str_replace('http://', 'https://',
60 CRM_Utils_System::url('civicrm/dashboard', 'reset=1', TRUE,
61 NULL, FALSE, FALSE
62 )
63 );
64 if (!CRM_Utils_System::checkURL($url, TRUE)) {
65 $errors = [
66 'enableSSL' => ts('You need to set up a secure server before you can use the Force Secure URLs option'),
67 ];
68 return $errors;
69 }
70 }
71 return TRUE;
72 }
73
74 public function postProcess() {
75 // if extensions url is set, lets clear session status messages to avoid
76 // a potentially spurious message which might already have been set. This
77 // is a bit hackish
78 // CRM-10629
79 $session = CRM_Core_Session::singleton();
80 $session->getStatus(TRUE);
81
82 parent::postProcess();
83
84 parent::rebuildMenu();
85 }
86
87 }