Skip to content

Commit

Permalink
Joomla 4.0 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpthompson committed Aug 28, 2019
1 parent 40a2af8 commit cb86c66
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
7 changes: 4 additions & 3 deletions admin/configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function civicrm_setup() {
}

$extractdir = $adminPath;
JArchive::extract($archivename, $extractdir);
$archive = new Joomla\Archive\Archive;
$archive->extract($archivename, $extractdir);
}

$scratchDir = JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'civicrm';
Expand Down Expand Up @@ -173,7 +174,7 @@ function civicrm_source($fileName, $lineMode = FALSE) {
}

if (!$lineMode) {
$string = JFile::read($fileName);
$string = file_get_contents($fileName);

//get rid of comments starting with # and --
$string = preg_replace("/^#[^\n]*$/m", "\n", $string);
Expand Down Expand Up @@ -233,7 +234,7 @@ function civicrm_config($frontend = FALSE, $siteKey) {
$params['baseURL'] = $liveSite . '/';
}

$str = JFile::read($adminPath . DIRECTORY_SEPARATOR .
$str = file_get_contents($adminPath . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'templates' . DIRECTORY_SEPARATOR .
'CRM' . DIRECTORY_SEPARATOR .
Expand Down
26 changes: 24 additions & 2 deletions admin/plugins/civicrm/civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ function onUserAfterDelete($user, $succes, $msg) {
* @since 1.6
*/
public function onUserLogin($user, $options = array()) {
$app = JFactory::getApplication();
if ($app->isAdmin()) {
if (self::isAdminBackend()) {
$jUser = JFactory::getUser();
$jId = $jUser->get('id');
self::civicrmResetNavigation($jId);
Expand Down Expand Up @@ -125,4 +124,27 @@ public function civicrmResetNavigation($jId = NULL) {
CRM_Core_BAO_Navigation::resetNavigation($cId);
}

/**
* Determine if we are in the Joomla administrator backend
*
* @return boolean True if in the Joomla Administrator backend otherwise false
*/
private function isAdminBackend() {
$app = JFactory::getApplication();

// Determine if we are in the Joomla administrator backend
// In Joomla 3.7+ the isClient() method is used. In earlier versions use the isAdmin() method (deprecated in Joomla 4.0).
if (method_exists($app, 'isClient')) {
$isAdmin = $app->isClient('administrator');
}
elseif (method_exists($app, 'isAdmin')) {
$isAdmin = $app->isAdmin();
}
else {
throw new \Exception("CiviCRM User Plugin error: no method found to determine Joomla client interface.");
}

return $isAdmin;
}

}
21 changes: 17 additions & 4 deletions script.civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,21 @@ function install($parent) {
</center>';
}

//install and enable plugins
$manifest = $parent->get("manifest");
// Install and enable plugins

// Get the installer manifest. Use the getManifest() method if it exists (Joomla 3.4+)
// If not then use get("manifest") (deprecated in Joomla 4.0).
if (method_exists($parent, 'getManifest')) {
$manifest = $parent->getManifest();
}
elseif (method_exists($parent, 'get')) {
$manifest = $parent->get("manifest");
}
else {
echo "No method found to get Joomla installer manifest.";
exit();
}

$parent = $parent->getParent();
$source = $parent->getPath("source");
$installer = new JInstaller();
Expand Down Expand Up @@ -130,7 +143,7 @@ function install($parent) {
WHERE $columnElement IN ($plgList)
AND $columnType = 'plugin'
");
$db->query();
$db->execute();

echo $content;
}
Expand Down Expand Up @@ -268,7 +281,7 @@ function setDefaultPermissions() {
' WHERE name = ' .
$db->quote('com_civicrm')
);
if (!$db->query()) {
if (!$db->execute()) {
echo 'Seems like setting default actions failed<p>';
}
}
Expand Down

0 comments on commit cb86c66

Please sign in to comment.