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() {
51 $this->is_drupal
= TRUE;
52 $this->supports_form_extensions
= TRUE;
56 * @param string dir base civicrm directory
57 * Return default Site Settings
59 * - $url, (Joomla - non admin url)
63 function getDefaultSiteSettings($dir){
64 $config = CRM_Core_Config
::singleton();
65 $siteName = $siteRoot = NULL;
68 '|/sites/([\w\.\-\_]+)/|',
69 $config->templateCompileDir
,
72 $siteName = $matches[1];
74 $siteName = "/sites/$siteName/";
75 $siteNamePos = strpos($dir, $siteName);
76 if ($siteNamePos !== FALSE) {
77 $siteRoot = substr($dir, 0, $siteNamePos);
81 $url = $config->userFrameworkBaseURL
;
82 return array($url, $siteName, $siteRoot);
86 * Check if a resource url is within the drupal directory and format appropriately
88 * @param url (reference)
90 * @return bool: TRUE for internal paths, FALSE for external. The drupal_add_js fn is able to add js more
91 * efficiently if it is known to be in the drupal site
93 function formatResourceUrl(&$url) {
95 $base = CRM_Core_Config
::singleton()->resourceBase
;
97 // Handle absolute urls
98 // 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)
99 // to see if the url is within our drupal dir, if it is we are able to treated it as an internal url
100 if (strpos($url, $base_url) === 0) {
102 $url = trim(str_replace($base_url, '', $url), '/');
104 // Handle relative urls that are within the CiviCRM module directory
105 elseif (strpos($url, $base) === 0) {
107 $url = $this->appendCoreDirectoryToResourceBase(substr(drupal_get_path('module', 'civicrm'), 0, -6)) . trim(substr($url, strlen($base)), '/');
109 // Strip query string
110 $q = strpos($url, '?');
111 if ($q && $internal) {
112 $url = substr($url, 0, $q);
118 * In instance where civicrm folder has a drupal folder & a civicrm core folder @ the same level append the
119 * civicrm folder name to the url
120 * See CRM-13737 for discussion of how this allows implementers to alter the folder structure
121 * @todo - this only provides a limited amount of flexiblity - it still expects a 'civicrm' folder with a 'drupal' folder
122 * and is only flexible as to the name of the civicrm folder.
124 * @param string $url potential resource url based on standard folder assumptions
125 * @return string $url with civicrm-core directory appended if not standard civi dir
127 function appendCoreDirectoryToResourceBase($url) {
128 global $civicrm_root;
129 $lastDirectory = basename($civicrm_root);
130 if($lastDirectory != 'civicrm') {
131 return $url .= $lastDirectory . '/';
137 * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url)
139 * @param $path string The path being linked to, such as "civicrm/add"
140 * @param $query string A query string to append to the link.
141 * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
142 * Useful for links that will be displayed outside the site, such as in an
144 * @param $fragment string A fragment identifier (named anchor) to append to the link.
145 * @param $htmlize boolean whether to convert to html eqivalant
146 * @param $frontend boolean a gross joomla hack
147 * @param $forceBackend boolean a gross joomla hack
149 * @return string an HTML string containing a link to the given path.
153 function url($path = NULL, $query = NULL, $absolute = FALSE,
154 $fragment = NULL, $htmlize = TRUE,
155 $frontend = FALSE, $forceBackend = FALSE
157 $config = CRM_Core_Config
::singleton();
158 $script = 'index.php';
160 $path = CRM_Utils_String
::stripPathChars($path);
162 if (isset($fragment)) {
163 $fragment = '#' . $fragment;
166 if (!isset($config->useFrameworkRelativeBase
)) {
167 $base = parse_url($config->userFrameworkBaseURL
);
168 $config->useFrameworkRelativeBase
= $base['path'];
170 $base = $absolute ?
$config->userFrameworkBaseURL
: $config->useFrameworkRelativeBase
;
172 $separator = $htmlize ?
'&' : '&';
174 if (!$config->cleanURL
) {
177 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
180 return $base . $script . '?q=' . $path . $fragment;
185 return $base . $script . '?' . $query . $fragment;
188 return $base . $fragment;
195 return $base . $path . '?' . $query . $fragment;
198 return $base . $path . $fragment;
203 return $base . $script . '?' . $query . $fragment;
206 return $base . $fragment;
213 * Get User ID from UserFramework system (Drupal)
214 * @param object $user object as described by the CMS
215 * @return mixed <NULL, number>
217 function getUserIDFromUserObject($user) {
218 return !empty($user->uid
) ?
$user->uid
: NULL;
222 * Get Unique Identifier from UserFramework system (CMS)
223 * @param object $user object as described by the User Framework
224 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
227 function getUniqueIdentifierFromUserObject($user) {
228 return empty($user->mail
) ?
NULL : $user->mail
;
232 * Get currently logged in user unique identifier - this tends to be the email address or user name.
234 * @return string $userID logged in user unique identifier
236 function getLoggedInUniqueIdentifier() {
238 return $this->getUniqueIdentifierFromUserObject($user);
242 * Action to take when access is not permitted
244 function permissionDenied() {
245 drupal_access_denied();
249 * Get Url to view user record
250 * @param integer $contactID Contact ID
254 function getUserRecordUrl($contactID) {
255 $uid = CRM_Core_BAO_UFMatch
::getUFId($contactID);
256 if (CRM_Core_Session
::singleton()->get('userID') == $contactID || CRM_Core_Permission
::checkAnyPerm(array('cms:administer users', 'cms:view user account'))) {
257 return CRM_Utils_System
::url('user/' . $uid);
262 * Is the current user permitted to add a user
265 function checkPermissionAddUser() {
266 if (CRM_Core_Permission
::check('administer users')) {
275 function logger($message) {
276 if (CRM_Core_Config
::singleton()->userFrameworkLogging
) {
277 watchdog('civicrm', $message, NULL, WATCHDOG_DEBUG
);