Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * Base class for UF system integrations | |
5 | */ | |
6 | abstract class CRM_Utils_System_Base { | |
7 | var $is_drupal = FALSE; | |
8 | var $is_joomla = FALSE; | |
9 | var $is_wordpress = FALSE; | |
10 | ||
11 | /* | |
12 | * Does the CMS allow CMS forms to be extended by hooks | |
13 | */ | |
14 | var $supports_form_extensions = FALSE; | |
15 | ||
16 | /** | |
17 | * if we are using a theming system, invoke theme, else just print the | |
18 | * content | |
19 | * | |
20 | * @param string $content the content that will be themed | |
21 | * @param boolean $print are we displaying to the screen or bypassing theming? | |
22 | * @param boolean $maintenance for maintenance mode | |
23 | * | |
24 | * @return void prints content on stdout | |
25 | * @access public | |
26 | */ | |
27 | function theme(&$content, $print = FALSE, $maintenance = FALSE) { | |
28 | $ret = FALSE; | |
29 | ||
30 | // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function | |
31 | // but the parts should be copied into cleaner subclass implementations | |
1e305b0b DL |
32 | $config = CRM_Core_Config::singleton(); |
33 | if ( | |
34 | $config->userSystem->is_drupal && | |
35 | function_exists('theme') && | |
36 | ||
37 | ) { | |
6a488035 TO |
38 | if ($maintenance) { |
39 | drupal_set_breadcrumb(''); | |
40 | drupal_maintenance_theme(); | |
10221f8a TO |
41 | if ($region = CRM_Core_Region::instance('html-header', FALSE)) { |
42 | CRM_Utils_System::addHTMLHead($region->render('')); | |
43 | } | |
6a488035 TO |
44 | print theme('maintenance_page', array('content' => $content)); |
45 | exit(); | |
46 | } | |
47 | $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints | |
48 | } | |
49 | $out = $content; | |
50 | ||
51 | $config = &CRM_Core_Config::singleton(); | |
1e305b0b DL |
52 | if ( |
53 | !$print && | |
6a488035 TO |
54 | $config->userFramework == 'WordPress' |
55 | ) { | |
56 | if (is_admin()) { | |
57 | require_once (ABSPATH . 'wp-admin/admin-header.php'); | |
58 | } | |
59 | else { | |
60 | // FIX ME: we need to figure out to replace civicrm content on the frontend pages | |
61 | } | |
62 | } | |
63 | ||
64 | if ($ret) { | |
65 | return $out; | |
66 | } | |
67 | else { | |
68 | print $out; | |
69 | } | |
70 | } | |
71 | ||
72 | function getDefaultBlockLocation() { | |
73 | return 'left'; | |
74 | } | |
75 | ||
76 | function getVersion() { | |
77 | return 'Unknown'; | |
78 | } | |
79 | ||
80 | /** | |
81 | * Format the url as per language Negotiation. | |
82 | * | |
83 | * @param string $url | |
84 | * | |
85 | * @return string $url, formatted url. | |
86 | * @static | |
87 | */ | |
88 | function languageNegotiationURL( | |
89 | $url, | |
90 | $addLanguagePart = TRUE, | |
91 | $removeLanguagePart = FALSE | |
92 | ) { | |
93 | return $url; | |
94 | } | |
95 | ||
e29aefb4 TO |
96 | /** |
97 | * Determine the location of the CMS root. | |
98 | * | |
99 | * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined | |
6a488035 TO |
100 | */ |
101 | function cmsRootPath() { | |
e29aefb4 | 102 | return NULL; |
6a488035 TO |
103 | } |
104 | ||
105 | /** | |
106 | * Get user login URL for hosting CMS (method declared in each CMS system class) | |
107 | * | |
108 | * @param string $destination - if present, add destination to querystring (works for Drupal only) | |
109 | * | |
110 | * @return string - loginURL for the current CMS | |
111 | * @static | |
112 | */ | |
113 | public abstract function getLoginURL($destination = ''); | |
114 | ||
46b6363c TO |
115 | /** |
116 | * Determine the native ID of the CMS user | |
117 | * | |
118 | * @param $username | |
119 | * @return int|NULL | |
120 | */ | |
121 | function getUfId($username) { | |
122 | $className = get_class($this); | |
123 | throw new CRM_Core_Exception("Not implemented: {$className}->getUfId"); | |
124 | } | |
125 | ||
5d0eb86b BS |
126 | /** |
127 | * Set a init session with user object | |
128 | * | |
129 | * @param array $data array with user specific data | |
130 | * | |
131 | * @access public | |
132 | */ | |
133 | function setUserSession($data) { | |
134 | list($userID, $ufID) = $data; | |
135 | $session = CRM_Core_Session::singleton(); | |
136 | $session->set('ufID', $ufID); | |
137 | $session->set('userID', $userID); | |
138 | } | |
d8a4acc0 C |
139 | |
140 | /** | |
141 | * Reset any system caches that may be required for proper CiviCRM | |
142 | * integration. | |
143 | */ | |
144 | function flush() { | |
145 | // nullop by default | |
146 | } | |
82d9c21e | 147 | |
c8950569 | 148 | /** |
9977c6f5 | 149 | * Return default Site Settings |
150 | * @return array array | |
151 | * - $url, (Joomla - non admin url) | |
152 | * - $siteName, | |
153 | * - $siteRoot | |
154 | */ | |
c8950569 | 155 | function getDefaultSiteSettings($dir) { |
9977c6f5 | 156 | $config = CRM_Core_Config::singleton(); |
157 | $url = $config->userFrameworkBaseURL; | |
158 | return array($url, NULL, NULL); | |
159 | } | |
c8950569 | 160 | |
82d9c21e | 161 | /** |
95d68223 | 162 | * Perform any post login activities required by the CMS - |
53980972 | 163 | * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, |
164 | * calls hook_user op 'login' and generates a new session. | |
e43cc689 | 165 | * |
95d68223 TO |
166 | * @param array params |
167 | * | |
168 | * FIXME: Document values accepted/required by $params | |
c8950569 | 169 | */ |
53980972 | 170 | function userLoginFinalize($params = array()){ |
82d9c21e | 171 | } |
5a604d61 E |
172 | |
173 | /** | |
174 | * Set timezone in mysql so that timestamp fields show the correct time | |
175 | */ | |
176 | function setMySQLTimeZone(){ | |
177 | $timeZoneOffset = $this->getTimeZoneOffset(); | |
178 | if($timeZoneOffset){ | |
179 | $sql = "SET time_zone = '$timeZoneOffset'"; | |
180 | CRM_Core_DAO::executequery($sql); | |
181 | } | |
182 | } | |
183 | ||
6491539b | 184 | |
5a604d61 E |
185 | /** |
186 | * Get timezone from CMS | |
187 | * @return boolean|string | |
188 | */ | |
6491539b DL |
189 | /** |
190 | * Get timezone from Drupal | |
191 | * @return boolean|string | |
192 | */ | |
5a604d61 | 193 | function getTimeZoneOffset(){ |
6491539b DL |
194 | $timezone = $this->getTimeZoneString(); |
195 | if($timezone){ | |
196 | $tzObj = new DateTimeZone($timezone); | |
197 | $dateTime = new DateTime("now", $tzObj); | |
198 | $tz = $tzObj->getOffset($dateTime); | |
199 | ||
200 | if(empty($tz)){ | |
201 | return false; | |
202 | } | |
203 | ||
204 | $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60 ); | |
205 | ||
206 | if($timeZoneOffset > 0){ | |
207 | $timeZoneOffset = '+' . $timeZoneOffset; | |
208 | } | |
209 | return $timeZoneOffset; | |
210 | } | |
211 | } | |
212 | ||
213 | /** | |
214 | * Over-ridable function to get timezone as a string eg. | |
215 | * @return string Timezone e.g. 'America/Los_Angeles' | |
216 | */ | |
217 | function getTimeZoneString() { | |
218 | return NULL; | |
5a604d61 | 219 | } |
6a488035 TO |
220 | } |
221 |