Example #1
0
 /**
  * load drupal bootstrap
  *
  * @param array $params Either uid, or name & pass.
  * @param boolean $loadUser boolean Require CMS user load.
  * @param boolean $throwError If true, print error on failure and exit.
  * @param boolean|string $realPath path to script
  */
 function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL)
 {
     //take the cms root path.
     $cmsPath = $this->cmsRootPath($realPath);
     if (!file_exists("{$cmsPath}/includes/bootstrap.inc")) {
         if ($throwError) {
             echo '<br />Sorry, could not locate bootstrap.inc\\n';
             exit;
         }
         return FALSE;
     }
     // load drupal bootstrap
     chdir($cmsPath);
     define('DRUPAL_ROOT', $cmsPath);
     // For drupal multi-site CRM-11313
     if ($realPath && strpos($realPath, 'sites/all/modules/') === FALSE) {
         preg_match('@sites/([^/]*)/modules@s', $realPath, $matches);
         if (!empty($matches[1])) {
             $_SERVER['HTTP_HOST'] = $matches[1];
         }
     }
     require_once 'includes/bootstrap.inc';
     // @ to suppress notices eg 'DRUPALFOO already defined'.
     @drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
     // explicitly setting error reporting, since we cannot handle drupal related notices
     error_reporting(1);
     if (!function_exists('module_exists') || !module_exists('civicrm')) {
         if ($throwError) {
             echo '<br />Sorry, could not load drupal bootstrap.';
             exit;
         }
         return FALSE;
     }
     // seems like we've bootstrapped drupal
     $config = CRM_Core_Config::singleton();
     // lets also fix the clean url setting
     // CRM-6948
     $config->cleanURL = (int) variable_get('clean_url', '0');
     // we need to call the config hook again, since we now know
     // all the modules that are listening on it, does not apply
     // to J! and WP as yet
     // CRM-8655
     CRM_Utils_Hook::config($config);
     if (!$loadUser) {
         return TRUE;
     }
     $uid = CRM_Utils_Array::value('uid', $params);
     if (!$uid) {
         //load user, we need to check drupal permissions.
         $name = CRM_Utils_Array::value('name', $params, FALSE) ? $params['name'] : trim(CRM_Utils_Array::value('name', $_REQUEST));
         $pass = CRM_Utils_Array::value('pass', $params, FALSE) ? $params['pass'] : trim(CRM_Utils_Array::value('pass', $_REQUEST));
         if ($name) {
             $uid = user_authenticate($name, $pass);
             if (!$uid) {
                 if ($throwError) {
                     echo '<br />Sorry, unrecognized username or password.';
                     exit;
                 }
                 return FALSE;
             }
         }
     }
     if ($uid) {
         $account = user_load($uid);
         if ($account && $account->uid) {
             global $user;
             $user = $account;
             return TRUE;
         }
     }
     if ($throwError) {
         echo '<br />Sorry, can not load CMS user account.';
         exit;
     }
     // CRM-6948: When using loadBootStrap, it's implicit that CiviCRM has already loaded its settings
     // which means that define(CIVICRM_CLEANURL) was correctly set.
     // So we correct it
     $config = CRM_Core_Config::singleton();
     $config->cleanURL = (int) variable_get('clean_url', '0');
     // CRM-8655: Drupal wasn't available during bootstrap, so hook_civicrm_config never executes
     CRM_Utils_Hook::config($config);
     return FALSE;
 }
 /**
  * load drupal bootstrap
  *
  * @param $name string  optional username for login
  * @param $pass string  optional password for login
  */
 function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL)
 {
     $uid = CRM_Utils_Array::value('uid', $params);
     $name = CRM_Utils_Array::value('name', $params, FALSE) ? $params['name'] : trim(CRM_Utils_Array::value('name', $_REQUEST));
     $pass = CRM_Utils_Array::value('pass', $params, FALSE) ? $params['pass'] : trim(CRM_Utils_Array::value('pass', $_REQUEST));
     //take the cms root path.
     $cmsPath = $this->cmsRootPath($realPath);
     if (!file_exists("{$cmsPath}/includes/bootstrap.inc")) {
         echo '<br />Sorry, unable to locate bootstrap.inc.';
         exit;
     }
     chdir($cmsPath);
     require_once 'includes/bootstrap.inc';
     @drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
     if (!function_exists('module_exists') || !module_exists('civicrm')) {
         echo '<br />Sorry, could not able to load drupal bootstrap.';
         exit;
     }
     // lets also fix the clean url setting
     // CRM-6948
     $config->cleanURL = (int) variable_get('clean_url', '0');
     // we need to call the config hook again, since we now know
     // all the modules that are listening on it, does not apply
     // to J! and WP as yet
     // CRM-8655
     CRM_Utils_Hook::config($config);
     if (!$loadUser) {
         return TRUE;
     }
     //load user, we need to check drupal permissions.
     if ($name) {
         $user = user_authenticate(array('name' => $name, 'pass' => $pass));
         if (empty($user->uid)) {
             echo '<br />Sorry, unrecognized username or password.';
             exit;
         }
     } elseif ($uid) {
         $account = user_load(array('uid' => $uid));
         if (empty($account->uid)) {
             echo '<br />Sorry, unrecognized user id.';
             exit;
         } else {
             global $user;
             $user = $account;
         }
     }
 }
Example #3
0
 /**
  * Singleton function used to manage this object.
  *
  * @param bool $loadFromDB
  *   whether to load from the database.
  * @param bool $force
  *   whether to force a reconstruction.
  *
  * @return CRM_Core_Config
  */
 public static function &singleton($loadFromDB = TRUE, $force = FALSE)
 {
     if (self::$_singleton === NULL || $force) {
         $GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'handle'));
         $errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'simpleHandler'));
         if (defined('E_DEPRECATED')) {
             error_reporting(error_reporting() & ~E_DEPRECATED);
         }
         self::$_singleton = new CRM_Core_Config();
         \Civi\Core\Container::boot($loadFromDB);
         if ($loadFromDB && self::$_singleton->dsn) {
             $domain = \CRM_Core_BAO_Domain::getDomain();
             \CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
             unset($errorScope);
             CRM_Utils_Hook::config(self::$_singleton);
             self::$_singleton->authenticate();
             // Extreme backward compat: $config binds to active domain at moment of setup.
             self::$_singleton->getSettings();
             Civi::service('settings_manager')->useDefaults();
             self::$_singleton->handleFirstRun();
         }
     }
     return self::$_singleton;
 }
Example #4
0
 /**
  * Singleton function used to manage this object.
  *
  * @param $loadFromDB boolean  whether to load from the database
  * @param $force      boolean  whether to force a reconstruction
  *
  * @return object
  * @static
  */
 static function &singleton($loadFromDB = true, $force = false)
 {
     if (self::$_singleton === null || $force) {
         // first, attempt to get configuration object from cache
         require_once 'CRM/Utils/Cache.php';
         $cache =& CRM_Utils_Cache::singleton();
         self::$_singleton = $cache->get('CRM_Core_Config');
         // if not in cache, fire off config construction
         if (!self::$_singleton) {
             self::$_singleton = new CRM_Core_Config();
             self::$_singleton->_initialize();
             //initialize variables. for gencode we cannot load from the
             //db since the db might not be initialized
             if ($loadFromDB) {
                 self::$_singleton->_initVariables();
                 // retrieve and overwrite stuff from the settings file
                 self::$_singleton->setCoreVariables();
             }
             $cache->set('CRM_Core_Config', self::$_singleton);
         } else {
             // we retrieve the object from memcache, so we now initialize the objects
             self::$_singleton->_initialize();
             // add component specific settings
             self::$_singleton->componentRegistry->addConfig($this);
         }
         self::$_singleton->initialized = 1;
         if (isset(self::$_singleton->customPHPPathDir) && self::$_singleton->customPHPPathDir) {
             $include_path = self::$_singleton->customPHPPathDir . PATH_SEPARATOR . get_include_path();
             set_include_path($include_path);
         }
         // set the callback at the very very end, to avoid an infinite loop
         // set the error callback
         CRM_Core_Error::setCallback();
         // call the hook so other modules can add to the config
         // again doing this at the very very end
         require_once 'CRM/Utils/Hook.php';
         CRM_Utils_Hook::config(self::$_singleton);
     }
     return self::$_singleton;
 }
Example #5
0
 /**
  * Load joomla bootstrap.
  *
  * @param array $params
  *   with uid or name and password.
  * @param bool $loadUser
  *   load cms user?.
  * @param bool|\throw $throwError throw error on failure?
  * @param null $realPath
  * @param bool $loadDefines
  *
  * @return bool
  */
 public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL, $loadDefines = TRUE)
 {
     // Setup the base path related constant.
     $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
     // load BootStrap here if needed
     // We are a valid Joomla entry point.
     if (!defined('_JEXEC') && $loadDefines) {
         define('_JEXEC', 1);
         define('DS', DIRECTORY_SEPARATOR);
         define('JPATH_BASE', $joomlaBase . '/administrator');
         require $joomlaBase . '/administrator/includes/defines.php';
     }
     // Get the framework.
     if (file_exists($joomlaBase . '/libraries/import.legacy.php')) {
         require $joomlaBase . '/libraries/import.legacy.php';
     }
     require $joomlaBase . '/libraries/import.php';
     require $joomlaBase . '/libraries/joomla/event/dispatcher.php';
     require $joomlaBase . '/configuration.php';
     // Files may be in different places depending on Joomla version
     if (!defined('JVERSION')) {
         require $joomlaBase . '/libraries/cms/version/version.php';
         $jversion = new JVersion();
         define('JVERSION', $jversion->getShortVersion());
     }
     if (version_compare(JVERSION, '3.0', 'lt')) {
         require $joomlaBase . '/libraries/joomla/environment/uri.php';
         require $joomlaBase . '/libraries/joomla/application/component/helper.php';
     } else {
         require $joomlaBase . '/libraries/cms.php';
         require $joomlaBase . '/libraries/joomla/uri/uri.php';
     }
     jimport('joomla.application.cli');
     // CRM-14281 Joomla wasn't available during bootstrap, so hook_civicrm_config never executes.
     $config = CRM_Core_Config::singleton();
     CRM_Utils_Hook::config($config);
     return TRUE;
 }
Example #6
0
 /**
  * Singleton function used to manage this object.
  *
  * @param bool $loadFromDB
  *   whether to load from the database.
  * @param bool $force
  *   whether to force a reconstruction.
  *
  * @return CRM_Core_Config
  */
 public static function &singleton($loadFromDB = TRUE, $force = FALSE)
 {
     if (self::$_singleton === NULL || $force) {
         // goto a simple error handler
         $GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'handle'));
         $errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'simpleHandler'));
         // lets ensure we set E_DEPRECATED to minimize errors
         // CRM-6327
         if (defined('E_DEPRECATED')) {
             error_reporting(error_reporting() & ~E_DEPRECATED);
         }
         // first, attempt to get configuration object from cache
         $cache = CRM_Utils_Cache::singleton();
         self::$_singleton = $cache->get('CRM_Core_Config' . CRM_Core_Config::domainID());
         // if not in cache, fire off config construction
         if (!self::$_singleton) {
             self::$_singleton = new CRM_Core_Config();
             self::$_singleton->_initialize($loadFromDB);
             //initialize variables. for gencode we cannot load from the
             //db since the db might not be initialized
             if ($loadFromDB) {
                 // initialize stuff from the settings file
                 self::$_singleton->setCoreVariables();
                 self::$_singleton->_initVariables();
                 // I don't think we need to do this twice
                 // however just keeping this commented for now in 4.4
                 // in case we hit any issues - CRM-13064
                 // We can safely delete this once we release 4.4.4
                 // self::$_singleton->setCoreVariables();
             }
             $cache->set('CRM_Core_Config' . CRM_Core_Config::domainID(), self::$_singleton);
         } else {
             // we retrieve the object from memcache, so we now initialize the objects
             self::$_singleton->_initialize($loadFromDB);
             // CRM-9803, NYSS-4822
             // this causes various settings to be reset and hence we should
             // only use the config object that we retrieved from memcache
         }
         self::$_singleton->initialized = 1;
         if (isset(self::$_singleton->customPHPPathDir) && self::$_singleton->customPHPPathDir) {
             $include_path = self::$_singleton->customPHPPathDir . PATH_SEPARATOR . get_include_path();
             set_include_path($include_path);
         }
         // set the callback at the very very end, to avoid an infinite loop
         // set the error callback
         unset($errorScope);
         // call the hook so other modules can add to the config
         // again doing this at the very very end
         CRM_Utils_Hook::config(self::$_singleton);
         // make sure session is always initialised
         $session = CRM_Core_Session::singleton();
         // for logging purposes, pass the userID to the db
         $userID = $session->get('userID');
         if ($userID) {
             CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($userID, 'Integer')));
         }
         // initialize authentication source
         self::$_singleton->initAuthSrc();
     }
     return self::$_singleton;
 }
Example #7
0
 /**
  * Load drupal bootstrap.
  *
  * @param array $params
  *   Either uid, or name & pass.
  * @param bool $loadUser
  *   Boolean Require CMS user load.
  * @param bool $throwError
  *   If true, print error on failure and exit.
  * @param bool|string $realPath path to script
  *
  * @return bool
  * @Todo Handle setting cleanurls configuration for CiviCRM?
  */
 public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL)
 {
     static $run_once = FALSE;
     if ($run_once) {
         return TRUE;
     } else {
         $run_once = TRUE;
     }
     if (!($root = $this->cmsRootPath())) {
         return FALSE;
     }
     chdir($root);
     // Create a mock $request object
     $autoloader = (require_once $root . '/vendor/autoload.php');
     // @Todo: do we need to handle case where $_SERVER has no HTTP_HOST key, ie. when run via cli?
     $request = new \Symfony\Component\HttpFoundation\Request(array(), array(), array(), array(), array(), $_SERVER);
     // Create a kernel and boot it.
     \Drupal\Core\DrupalKernel::createFromRequest($request, $autoloader, 'prod')->prepareLegacyRequest($request);
     // Initialize Civicrm
     \Drupal::service('civicrm');
     // We need to call the config hook again, since we now know
     // all the modules that are listening on it (CRM-8655).
     CRM_Utils_Hook::config($config);
     if ($loadUser) {
         if (!empty($params['uid']) && ($username = \Drupal\user\Entity\User::load($uid)->getUsername())) {
             $this->loadUser($username);
         } elseif (!empty($params['name']) && !empty($params['pass']) && $this->authenticate($params['name'], $params['pass'])) {
             $this->loadUser($params['name']);
         }
     }
     return TRUE;
 }
 /**
  * Singleton function used to manage this object.
  *
  * @param $loadFromDB boolean  whether to load from the database
  * @param $force      boolean  whether to force a reconstruction
  *
  * @return object
  * @static
  */
 static function &singleton($loadFromDB = TRUE, $force = FALSE)
 {
     if (self::$_singleton === NULL || $force) {
         // goto a simple error handler
         $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
         $GLOBALS['_PEAR_default_error_options'] = array('CRM_Core_Error', 'simpleHandler');
         // lets ensure we set E_DEPRECATED to minimize errors
         // CRM-6327
         if (defined('E_DEPRECATED')) {
             error_reporting(error_reporting() & ~E_DEPRECATED);
         }
         // first, attempt to get configuration object from cache
         $cache = CRM_Utils_Cache::singleton();
         self::$_singleton = $cache->get('CRM_Core_Config');
         // if not in cache, fire off config construction
         if (!self::$_singleton) {
             self::$_singleton = new CRM_Core_Config();
             self::$_singleton->_initialize($loadFromDB);
             //initialize variables. for gencode we cannot load from the
             //db since the db might not be initialized
             if ($loadFromDB) {
                 self::$_singleton->_initVariables();
                 // retrieve and overwrite stuff from the settings file
                 self::$_singleton->setCoreVariables();
             }
             $cache->set('CRM_Core_Config', self::$_singleton);
         } else {
             // we retrieve the object from memcache, so we now initialize the objects
             self::$_singleton->_initialize($loadFromDB);
             // CRM-9803, NYSS-4822
             // this causes various settings to be reset and hence we should
             // only use the config object that we retrived from memcache
         }
         self::$_singleton->initialized = 1;
         if (isset(self::$_singleton->customPHPPathDir) && self::$_singleton->customPHPPathDir) {
             $include_path = self::$_singleton->customPHPPathDir . PATH_SEPARATOR . get_include_path();
             set_include_path($include_path);
         }
         // set the callback at the very very end, to avoid an infinite loop
         // set the error callback
         CRM_Core_Error::setCallback();
         // call the hook so other modules can add to the config
         // again doing this at the very very end
         CRM_Utils_Hook::config(self::$_singleton);
         // make sure session is always initialised
         $session = CRM_Core_Session::singleton();
         // for logging purposes, pass the userID to the db
         $userID = $session->get('userID');
         if ($userID) {
             CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($userID, 'Integer')));
         }
     }
     return self::$_singleton;
 }