4 * Base class for UF system integrations
6 abstract class CRM_Utils_System_Base
{
7 var $is_drupal = FALSE;
8 var $is_joomla = FALSE;
9 var $is_wordpress = FALSE;
12 * Does the CMS allow CMS forms to be extended by hooks
14 var $supports_form_extensions = FALSE;
17 * if we are using a theming system, invoke theme, else just print the
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
24 * @return void prints content on stdout
27 function theme(&$content, $print = FALSE, $maintenance = FALSE) {
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 $config = CRM_Core_Config
::singleton();
34 $config->userSystem
->is_drupal
&&
35 function_exists('theme') &&
39 drupal_set_breadcrumb('');
40 drupal_maintenance_theme();
41 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
42 CRM_Utils_System
::addHTMLHead($region->render(''));
44 print theme('maintenance_page', array('content' => $content));
47 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
51 $config = &CRM_Core_Config
::singleton();
54 $config->userFramework
== 'WordPress'
57 require_once (ABSPATH
. 'wp-admin/admin-header.php');
60 // FIX ME: we need to figure out to replace civicrm content on the frontend pages
72 function getDefaultBlockLocation() {
76 function getVersion() {
81 * Format the url as per language Negotiation.
85 * @return string $url, formatted url.
88 function languageNegotiationURL(
90 $addLanguagePart = TRUE,
91 $removeLanguagePart = FALSE
97 * Determine the location of the CMS root.
99 * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined
101 function cmsRootPath() {
106 * Get user login URL for hosting CMS (method declared in each CMS system class)
108 * @param string $destination - if present, add destination to querystring (works for Drupal only)
110 * @return string - loginURL for the current CMS
113 public abstract function getLoginURL($destination = '');
116 * Determine the native ID of the CMS user
121 function getUfId($username) {
122 $className = get_class($this);
123 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
127 * Set a init session with user object
129 * @param array $data array with user specific data
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);
141 * Reset any system caches that may be required for proper CiviCRM
149 * Return default Site Settings
150 * @return array array
151 * - $url, (Joomla - non admin url)
155 function getDefaultSiteSettings($dir) {
156 $config = CRM_Core_Config
::singleton();
157 $url = $config->userFrameworkBaseURL
;
158 return array($url, NULL, NULL);
162 * Perform any post login activities required by the CMS -
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.
166 * @param array params
168 * FIXME: Document values accepted/required by $params
170 function userLoginFinalize($params = array()){
174 * Set timezone in mysql so that timestamp fields show the correct time
176 function setMySQLTimeZone(){
177 $timeZoneOffset = $this->getTimeZoneOffset();
179 $sql = "SET time_zone = '$timeZoneOffset'";
180 CRM_Core_DAO
::executequery($sql);
186 * Get timezone from CMS
187 * @return boolean|string
190 * Get timezone from Drupal
191 * @return boolean|string
193 function getTimeZoneOffset(){
194 $timezone = $this->getTimeZoneString();
196 $tzObj = new DateTimeZone($timezone);
197 $dateTime = new DateTime("now", $tzObj);
198 $tz = $tzObj->getOffset($dateTime);
204 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60
);
206 if($timeZoneOffset > 0){
207 $timeZoneOffset = '+' . $timeZoneOffset;
209 return $timeZoneOffset;
214 * Over-ridable function to get timezone as a string eg.
215 * @return string Timezone e.g. 'America/Los_Angeles'
217 function getTimeZoneString() {