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
{
43 function __construct() {
44 $this->is_drupal
= TRUE;
45 $this->supports_form_extensions
= TRUE;
49 * @param string dir base civicrm directory
50 * Return default Site Settings
52 * - $url, (Joomla - non admin url)
56 function getDefaultSiteSettings($dir){
57 $config = CRM_Core_Config
::singleton();
58 $siteName = $siteRoot = NULL;
61 '|/sites/([\w\.\-\_]+)/|',
62 $config->templateCompileDir
,
65 $siteName = $matches[1];
67 $siteName = "/sites/$siteName/";
68 $siteNamePos = strpos($dir, $siteName);
69 if ($siteNamePos !== FALSE) {
70 $siteRoot = substr($dir, 0, $siteNamePos);
74 $url = $config->userFrameworkBaseURL
;
75 return array($url, $siteName, $siteRoot);
79 * Check if a resource url is within the drupal directory and format appropriately
81 * @param url (reference)
83 * @return bool: TRUE for internal paths, FALSE for external. The drupal_add_js fn is able to add js more
84 * efficiently if it is known to be in the drupal site
86 function formatResourceUrl(&$url) {
88 $base = CRM_Core_Config
::singleton()->resourceBase
;
90 // Handle absolute urls
91 // 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)
92 // to see if the url is within our drupal dir, if it is we are able to treated it as an internal url
93 if (strpos($url, $base_url) === 0) {
95 $url = trim(str_replace($base_url, '', $url), '/');
97 // Handle relative urls that are within the CiviCRM module directory
98 elseif (strpos($url, $base) === 0) {
100 $url = $this->appendCoreDirectoryToResourceBase(substr(drupal_get_path('module', 'civicrm'), 0, -6)) . trim(substr($url, strlen($base)), '/');
102 // Strip query string
103 $q = strpos($url, '?');
104 if ($q && $internal) {
105 $url = substr($url, 0, $q);
111 * In instance where civicrm folder has a drupal folder & a civicrm core folder @ the same level append the
112 * civicrm folder name to the url
113 * See CRM-13737 for discussion of how this allows implementers to alter the folder structure
114 * @todo - this only provides a limited amount of flexiblity - it still expects a 'civicrm' folder with a 'drupal' folder
115 * and is only flexible as to the name of the civicrm folder.
117 * @param string $url potential resource url based on standard folder assumptions
118 * @return string $url with civicrm-core directory appended if not standard civi dir
120 function appendCoreDirectoryToResourceBase($url) {
121 global $civicrm_root;
122 $lastDirectory = basename($civicrm_root);
123 if($lastDirectory != 'civicrm') {
124 return $url .= $lastDirectory . '/';
130 * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url)
132 * @param $path string The path being linked to, such as "civicrm/add"
133 * @param $query string A query string to append to the link.
134 * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
135 * Useful for links that will be displayed outside the site, such as in an
137 * @param $fragment string A fragment identifier (named anchor) to append to the link.
138 * @param $htmlize boolean whether to convert to html eqivalant
139 * @param $frontend boolean a gross joomla hack
140 * @param $forceBackend boolean a gross joomla hack
142 * @return string an HTML string containing a link to the given path.
146 function url($path = NULL, $query = NULL, $absolute = FALSE,
147 $fragment = NULL, $htmlize = TRUE,
148 $frontend = FALSE, $forceBackend = FALSE
150 $config = CRM_Core_Config
::singleton();
151 $script = 'index.php';
153 $path = CRM_Utils_String
::stripPathChars($path);
155 if (isset($fragment)) {
156 $fragment = '#' . $fragment;
159 if (!isset($config->useFrameworkRelativeBase
)) {
160 $base = parse_url($config->userFrameworkBaseURL
);
161 $config->useFrameworkRelativeBase
= $base['path'];
163 $base = $absolute ?
$config->userFrameworkBaseURL
: $config->useFrameworkRelativeBase
;
165 $separator = $htmlize ?
'&' : '&';
167 if (!$config->cleanURL
) {
170 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
173 return $base . $script . '?q=' . $path . $fragment;
178 return $base . $script . '?' . $query . $fragment;
181 return $base . $fragment;
188 return $base . $path . '?' . $query . $fragment;
191 return $base . $path . $fragment;
196 return $base . $script . '?' . $query . $fragment;
199 return $base . $fragment;
206 * Get User ID from UserFramework system (Drupal)
207 * @param object $user object as described by the CMS
208 * @return mixed <NULL, number>
210 function getUserIDFromUserObject($user) {
211 return !empty($user->uid
) ?
$user->uid
: NULL;
215 * Get Unique Identifier from UserFramework system (CMS)
216 * @param object $user object as described by the User Framework
217 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
220 function getUniqueIdentifierFromUserObject($user) {
221 return empty($user->mail
) ?
NULL : $user->mail
;
225 * Get currently logged in user unique identifier - this tends to be the email address or user name.
227 * @return string $userID logged in user unique identifier
229 function getLoggedInUniqueIdentifier() {
231 return $this->getUniqueIdentifierFromUserObject($user);
235 * Action to take when access is not permitted
237 function permissionDenied() {
238 drupal_access_denied();
242 * Get Url to view user record
243 * @param integer $contactID Contact ID
247 function getUserRecordUrl($contactID) {
248 $uid = CRM_Core_BAO_UFMatch
::getUFId($contactID);
249 if (CRM_Core_Session
::singleton()->get('userID') == $contactID || CRM_Core_Permission
::checkAnyPerm(array('cms:administer users', 'cms:view user account'))) {
250 return CRM_Utils_System
::url('user/' . $uid);
255 * Is the current user permitted to add a user
258 function checkPermissionAddUser() {
259 if (CRM_Core_Permission
::check('administer users')) {