3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Drupal specific stuff goes here
39 abstract class CRM_Utils_System_DrupalBase
extends CRM_Utils_System_Base
{
42 * Does this CMS / UF support a CMS specific logging mechanism?
43 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
46 var $supports_UF_Logging = TRUE;
50 function __construct() {
52 * deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
53 * functions and leave the codebase oblivious to the type of CMS
57 $this->is_drupal
= TRUE;
58 $this->supports_form_extensions
= TRUE;
62 * @param string dir base civicrm directory
63 * Return default Site Settings
65 * - $url, (Joomla - non admin url)
69 function getDefaultSiteSettings($dir){
70 $config = CRM_Core_Config
::singleton();
71 $siteName = $siteRoot = NULL;
74 '|/sites/([\w\.\-\_]+)/|',
75 $config->templateCompileDir
,
78 $siteName = $matches[1];
80 $siteName = "/sites/$siteName/";
81 $siteNamePos = strpos($dir, $siteName);
82 if ($siteNamePos !== FALSE) {
83 $siteRoot = substr($dir, 0, $siteNamePos);
87 $url = $config->userFrameworkBaseURL
;
88 return array($url, $siteName, $siteRoot);
92 * Check if a resource url is within the drupal directory and format appropriately
94 * @param url (reference)
96 * @return bool: TRUE for internal paths, FALSE for external. The drupal_add_js fn is able to add js more
97 * efficiently if it is known to be in the drupal site
99 function formatResourceUrl(&$url) {
101 $base = CRM_Core_Config
::singleton()->resourceBase
;
103 // Handle absolute urls
104 // compares $url (which is some unknown/untrusted value from a third-party dev) to the CMS's base url (which is independent of civi's url)
105 // to see if the url is within our drupal dir, if it is we are able to treated it as an internal url
106 if (strpos($url, $base_url) === 0) {
108 $url = trim(str_replace($base_url, '', $url), '/');
110 // Handle relative urls that are within the CiviCRM module directory
111 elseif (strpos($url, $base) === 0) {
113 $url = $this->appendCoreDirectoryToResourceBase(substr(drupal_get_path('module', 'civicrm'), 0, -6)) . trim(substr($url, strlen($base)), '/');
115 // Strip query string
116 $q = strpos($url, '?');
117 if ($q && $internal) {
118 $url = substr($url, 0, $q);
124 * In instance where civicrm folder has a drupal folder & a civicrm core folder @ the same level append the
125 * civicrm folder name to the url
126 * See CRM-13737 for discussion of how this allows implementers to alter the folder structure
127 * @todo - this only provides a limited amount of flexiblity - it still expects a 'civicrm' folder with a 'drupal' folder
128 * and is only flexible as to the name of the civicrm folder.
130 * @param string $url potential resource url based on standard folder assumptions
131 * @return string $url with civicrm-core directory appended if not standard civi dir
133 function appendCoreDirectoryToResourceBase($url) {
134 global $civicrm_root;
135 $lastDirectory = basename($civicrm_root);
136 if($lastDirectory != 'civicrm') {
137 return $url .= $lastDirectory . '/';
143 * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url)
145 * @param $path string The path being linked to, such as "civicrm/add"
146 * @param $query string A query string to append to the link.
147 * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
148 * Useful for links that will be displayed outside the site, such as in an
150 * @param $fragment string A fragment identifier (named anchor) to append to the link.
151 * @param $htmlize boolean whether to convert to html eqivalant
152 * @param $frontend boolean a gross joomla hack
153 * @param $forceBackend boolean a gross joomla hack
155 * @return string an HTML string containing a link to the given path.
159 function url($path = NULL, $query = NULL, $absolute = FALSE,
160 $fragment = NULL, $htmlize = TRUE,
161 $frontend = FALSE, $forceBackend = FALSE
163 $config = CRM_Core_Config
::singleton();
164 $script = 'index.php';
166 $path = CRM_Utils_String
::stripPathChars($path);
168 if (isset($fragment)) {
169 $fragment = '#' . $fragment;
172 if (!isset($config->useFrameworkRelativeBase
)) {
173 $base = parse_url($config->userFrameworkBaseURL
);
174 $config->useFrameworkRelativeBase
= $base['path'];
176 $base = $absolute ?
$config->userFrameworkBaseURL
: $config->useFrameworkRelativeBase
;
178 $separator = $htmlize ?
'&' : '&';
180 if (!$config->cleanURL
) {
183 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
186 return $base . $script . '?q=' . $path . $fragment;
191 return $base . $script . '?' . $query . $fragment;
194 return $base . $fragment;
201 return $base . $path . '?' . $query . $fragment;
204 return $base . $path . $fragment;
209 return $base . $script . '?' . $query . $fragment;
212 return $base . $fragment;
219 * Get User ID from UserFramework system (Drupal)
220 * @param object $user object as described by the CMS
221 * @return mixed <NULL, number>
223 function getUserIDFromUserObject($user) {
224 return !empty($user->uid
) ?
$user->uid
: NULL;
228 * Get Unique Identifier from UserFramework system (CMS)
229 * @param object $user object as described by the User Framework
230 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
233 function getUniqueIdentifierFromUserObject($user) {
234 return empty($user->mail
) ?
NULL : $user->mail
;
238 * Get currently logged in user unique identifier - this tends to be the email address or user name.
240 * @return string $userID logged in user unique identifier
242 function getLoggedInUniqueIdentifier() {
244 return $this->getUniqueIdentifierFromUserObject($user);
248 * Action to take when access is not permitted
250 function permissionDenied() {
251 drupal_access_denied();
255 * Get Url to view user record
256 * @param integer $contactID Contact ID
260 function getUserRecordUrl($contactID) {
261 $uid = CRM_Core_BAO_UFMatch
::getUFId($contactID);
262 if (CRM_Core_Session
::singleton()->get('userID') == $contactID || CRM_Core_Permission
::checkAnyPerm(array('cms:administer users', 'cms:view user account'))) {
263 return CRM_Utils_System
::url('user/' . $uid);
268 * Is the current user permitted to add a user
271 function checkPermissionAddUser() {
272 if (CRM_Core_Permission
::check('administer users')) {
281 function logger($message) {
282 if (CRM_Core_Config
::singleton()->userFrameworkLogging
) {
283 watchdog('civicrm', $message, NULL, WATCHDOG_DEBUG
);
288 * Flush css/js caches
290 function clearResourceCache() {
291 _drupal_flush_css_js();