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