Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | */ | |
39 | class CRM_Core_BAO_Preferences { | |
40 | ||
b5c2afd0 EM |
41 | /** |
42 | * @param $params | |
43 | */ | |
6a488035 TO |
44 | static function fixAndStoreDirAndURL(&$params) { |
45 | $sql = " | |
46 | SELECT v.name as valueName, g.name as optionName | |
47 | FROM civicrm_option_value v, | |
48 | civicrm_option_group g | |
49 | WHERE ( g.name = 'directory_preferences' | |
50 | OR g.name = 'url_preferences' ) | |
51 | AND v.option_group_id = g.id | |
52 | AND v.is_active = 1 | |
53 | "; | |
54 | ||
55 | $dirParams = array(); | |
56 | $urlParams = array(); | |
57 | $dao = CRM_Core_DAO::executeQuery($sql); | |
58 | while ($dao->fetch()) { | |
59 | if (!isset($params[$dao->valueName])) { | |
60 | continue; | |
61 | } | |
62 | if ($dao->optionName == 'directory_preferences') { | |
63 | $dirParams[$dao->valueName] = CRM_Utils_Array::value($dao->valueName, $params, ''); | |
64 | } | |
65 | else { | |
66 | $urlParams[$dao->valueName] = CRM_Utils_Array::value($dao->valueName, $params, ''); | |
67 | } | |
68 | unset($params[$dao->valueName]); | |
69 | } | |
70 | ||
71 | if (!empty($dirParams)) { | |
72 | CRM_Core_BAO_Preferences::storeDirectoryOrURLPreferences($dirParams, 'directory'); | |
73 | } | |
74 | ||
75 | if (!empty($urlParams)) { | |
76 | CRM_Core_BAO_Preferences::storeDirectoryOrURLPreferences($urlParams, 'url'); | |
77 | } | |
78 | } | |
79 | ||
b5c2afd0 EM |
80 | /** |
81 | * @param $params | |
82 | * @param string $type | |
83 | */ | |
6a488035 TO |
84 | static function storeDirectoryOrURLPreferences(&$params, $type = 'directory') { |
85 | $optionName = ($type == 'directory') ? 'directory_preferences' : 'url_preferences'; | |
86 | ||
87 | $sql = " | |
88 | UPDATE civicrm_option_value v, | |
89 | civicrm_option_group g | |
90 | SET v.value = %1, | |
91 | v.is_active = 1 | |
92 | WHERE g.name = %2 | |
93 | AND v.option_group_id = g.id | |
94 | AND v.name = %3 | |
95 | "; | |
96 | ||
97 | foreach ($params as $name => $value) { | |
98 | // always try to store relative directory or url from CMS root | |
99 | if ($type == 'directory') { | |
100 | $value = CRM_Utils_File::relativeDirectory($value); | |
101 | } | |
102 | else { | |
103 | $value = CRM_Utils_System::relativeURL($value); | |
104 | } | |
105 | $sqlParams = array(1 => array($value, 'String'), | |
106 | 2 => array($optionName, 'String'), | |
107 | 3 => array($name, 'String'), | |
108 | ); | |
109 | CRM_Core_DAO::executeQuery($sql, $sqlParams); | |
110 | } | |
111 | } | |
112 | ||
b5c2afd0 EM |
113 | /** |
114 | * @param $params | |
115 | * @param bool $setInConfig | |
116 | */ | |
6a488035 TO |
117 | static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) { |
118 | if ($setInConfig) { | |
119 | $config = CRM_Core_Config::singleton(); | |
120 | } | |
121 | ||
122 | $sql = " | |
123 | SELECT v.name as valueName, v.value, g.name as optionName | |
124 | FROM civicrm_option_value v, | |
125 | civicrm_option_group g | |
126 | WHERE ( g.name = 'directory_preferences' | |
127 | OR g.name = 'url_preferences' ) | |
128 | AND v.option_group_id = g.id | |
129 | AND v.is_active = 1 | |
130 | "; | |
131 | ||
132 | ||
133 | $dao = CRM_Core_DAO::executeQuery($sql); | |
134 | while ($dao->fetch()) { | |
135 | if (!$dao->value) { | |
136 | continue; | |
137 | } | |
138 | if ($dao->optionName == 'directory_preferences') { | |
139 | $value = CRM_Utils_File::absoluteDirectory($dao->value); | |
140 | } | |
141 | else { | |
142 | // CRM-7622: we need to remove the language part | |
143 | $value = CRM_Utils_System::absoluteURL($dao->value, TRUE); | |
144 | } | |
145 | $params[$dao->valueName] = $value; | |
146 | if ($setInConfig) { | |
147 | $config->{$dao->valueName} = $value; | |
148 | } | |
149 | } | |
150 | } | |
151 | } | |
152 |