kcfinder error 500 in Joomla 4/5
When trying to change/browse a link or upload a file, kcfinder shows an error 500 as it fails to start the application.
https://civicrm.stackexchange.com/questions/47872/500-error-when-trying-to-browse-a-link
kcfinder uses an outdated method to initialise the application as since Joomla 4 Factory::getApplication()
no longer takes arguments.
From the J4 potential backward compatibility page: https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4
The function authenticate_joomla
in administrator/civicrm/packages/kcfinder/integration/civicrm.php
should be changed to the following
function authenticate_joomla($config) {
$joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
define( '_JEXEC', 1 );
define('JPATH_BASE', $joomlaBase);
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$container = \Joomla\CMS\Factory::getContainer();
$container->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
$mainframe = $container->get(\Joomla\CMS\Application\AdministratorApplication::class);
if (JFactory::getUser()->id == 0) {
return false;
}
return true;
}