Another set of PHPDoc fixes
[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 'defaultExternUrl' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
25 'userFrameworkResourceURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
26 'imageUploadURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
27 'customCSSURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
28 'extensionsURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
29 ];
30
31 /**
32 * Build the form object.
33 */
34 public function buildQuickForm() {
35 $this->setTitle(ts('Settings - Resource URLs'));
36 $settingFields = civicrm_api('setting', 'getfields', [
37 'version' => 3,
38 ]);
39
40 $this->addYesNo('enableSSL', ts('Force Secure URLs (SSL)'));
41 $this->addYesNo('verifySSL', ts('Verify SSL Certs'));
42 // FIXME: verifySSL should use $_settings instead of manually adding fields
43 $this->assign('verifySSL_description', $settingFields['values']['verifySSL']['description']);
44
45 $this->addFormRule(['CRM_Admin_Form_Setting_Url', 'formRule']);
46
47 parent::buildQuickForm();
48 }
49
50 /**
51 * @param array $fields
52 *
53 * @return array|bool
54 */
55 public static function formRule($fields) {
56 if (isset($fields['enableSSL']) &&
57 $fields['enableSSL']
58 ) {
59 $config = CRM_Core_Config::singleton();
60 $url = str_replace('http://', 'https://',
61 CRM_Utils_System::url('civicrm/dashboard', 'reset=1', TRUE,
62 NULL, FALSE, FALSE
63 )
64 );
65 if (!CRM_Utils_System::checkURL($url, TRUE)) {
66 $errors = [
67 'enableSSL' => ts('You need to set up a secure server before you can use the Force Secure URLs option'),
68 ];
69 return $errors;
70 }
71 }
72 return TRUE;
73 }
74
75 public function postProcess() {
76 // if extensions url is set, lets clear session status messages to avoid
77 // a potentially spurious message which might already have been set. This
78 // is a bit hackish
79 // CRM-10629
80 $session = CRM_Core_Session::singleton();
81 $session->getStatus(TRUE);
82
83 parent::postProcess();
84 }
85
86 }