Answers.Body: <p>Please change the file <code>administrator/civicrm/packages/kcfinder/integration/civicrm.php</code> and use the following code for the <code>function authenticate_joomla</code> near the end of the file (line 193 f.) to the following:</p>
  <pre><code>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' );
  
  if (version_compare(JVERSION, '4.0.0', 'lt')) {
      $mainframe = JFactory::getApplication('administrator');
      $mainframe-&gt;initialise();
      
      $user_id = JFactory::getUser()-&gt;id;
    } 
    else {
      $container = \Joomla\CMS\Factory::getContainer();
  
      $container-&gt;alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
  
      $app = $container-&gt;get(\Joomla\CMS\Application\AdministratorApplication::class);
      
      $user_id = Joomla\CMS\Factory::getUser()-&gt;id;
    }
  
    if (JFactory::getUser()-&gt;id == 0) {
      return false;
    }
    return true;
  }
  </code></pre>
  <p><strong>I tested this successfully.</strong></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-24T09:10:04.090Z
Answers.Text: We have to avoid using JFactory::getApplication('administrator') as since Joomla 4 'getApplication' no longer takes arguments. From the J4 potential backward compatibility page, https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4
Answers.UserDisplayName: Guitarman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-24T11:25:35.847Z
Answers.Text: I will test this first chance I get
Answers.UserDisplayName: Larry G. Wapnitsky
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-29T15:12:52.560Z
Answers.Text: could you test this already?
Answers.UserDisplayName: Guitarman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-24T09:02:52.127Z
Answers.LastActivityDate: 2024-04-24T11:19:16.353Z
Answers.LastEditDate: 2024-04-24T11:19:16.353Z
Answers.UserDisplayName: Guitarman
Answers.Body: <p>Have you tried using <a href="https://civicrm.org/extensions/ckeditor-5" rel="nofollow noreferrer">CKeditor5</a> or <a href="https://civicrm.org/extensions/summernote" rel="nofollow noreferrer">summernote</a> as a replacement got Kcfinder?</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-24T11:25:03.377Z
Answers.Text: Ckeditor is fine, but you lose the ability to browse for links
Answers.UserDisplayName: Larry G. Wapnitsky
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-22T14:01:41.623Z
Answers.LastActivityDate: 2024-04-22T14:01:41.623Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>Receiving the following error when trying to browse for a link in Message templates:</p>
  <pre><code>Exception:
  Failed to start application
  
    at /var/www/joomla/libraries/src/Factory.php:158
    at Joomla\CMS\Factory::getApplication()
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php:203)
    at authenticate_joomla()
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php:73)
    at checkAuthentication()
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php:212)
    at require('/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php')
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/core/bootstrap.php:39)
    at require('/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/core/bootstrap.php')
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/browse.php:15)           
  </code></pre>
  <p>How can i resolve?</p>
  <p><a href="https://i.sstatic.net/sh8KL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sh8KL.png" alt="enter image description here" /></a>
  <a href="https://i.sstatic.net/RHonz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RHonz.png" alt="enter image description here" /></a>
  <a href="https://i.sstatic.net/O2zPH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/O2zPH.png" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-16T16:15:12.090Z
Comments.Text: I'd try to replace line 203 in ../civicrm.php as "JFactory::" is deprecated in Joomla 5 and must be replaced. I raised an issue 6 days ago. https://lab.civicrm.org/dev/joomla/-/issues/55
Comments.UserDisplayName: Guitarman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-17T07:53:56.860Z
Comments.Text: this is in joomla 4
Comments.UserDisplayName: Larry G. Wapnitsky
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-17T08:00:13.033Z
Comments.Text: made changes per your proposed change, and Factory could no longer be found
Comments.UserDisplayName: Larry G. Wapnitsky
Tags: <joomla>
Title: 500 error when trying to browse a link
ThreadText: # 500 error when trying to browse a link
  
  (Asked by: username_0 on 2024-04-14)
  
  Receiving the following error when trying to browse for a link in Message templates:
  
  ```
  Exception:
  Failed to start application
  
    at /var/www/joomla/libraries/src/Factory.php:158
    at Joomla\CMS\Factory::getApplication()
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php:203)
    at authenticate_joomla()
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php:73)
    at checkAuthentication()
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php:212)
    at require('/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/integration/civicrm.php')
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/core/bootstrap.php:39)
    at require('/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/core/bootstrap.php')
       (/var/www/joomla/administrator/components/com_civicrm/civicrm/packages/kcfinder/browse.php:15)           
  
  ```
  
  How can i resolve?
  
  [![enter image description here](https://i.sstatic.net/sh8KL.png)](https://i.sstatic.net/sh8KL.png)
  [![enter image description here](https://i.sstatic.net/RHonz.png)](https://i.sstatic.net/RHonz.png)
  [![enter image description here](https://i.sstatic.net/O2zPH.png)](https://i.sstatic.net/O2zPH.png)
  
  **Tags:** joomla
  
  > **Comments:**
  > **username_1**: I'd try to replace line 203 in ../civicrm.php as "JFactory::" is deprecated in Joomla 5 and must be replaced. I raised an issue 6 days ago. https://lab.civicrm.org/dev/joomla/-/issues/55  
  > **username_0**: this is in joomla 4  
  > **username_0**: made changes per your proposed change, and Factory could no longer be found  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-04-24. Score: 1
  
  Please change the file `administrator/civicrm/packages/kcfinder/integration/civicrm.php` and use the following code for the `function authenticate_joomla` near the end of the file (line 193 f.) 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' );
  
  if (version_compare(JVERSION, '4.0.0', 'lt')) {
      $mainframe = JFactory::getApplication('administrator');
      $mainframe->initialise();
      
      $user_id = JFactory::getUser()->id;
    } 
    else {
      $container = \Joomla\CMS\Factory::getContainer();
  
      $container->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
  
      $app = $container->get(\Joomla\CMS\Application\AdministratorApplication::class);
      
      $user_id = Joomla\CMS\Factory::getUser()->id;
    }
  
    if (JFactory::getUser()->id == 0) {
      return false;
    }
    return true;
  }
  
  ```
  
  **I tested this successfully.**
  
  > **Comments:**
  > **username_1**: We have to avoid using JFactory::getApplication('administrator') as since Joomla 4 'getApplication' no longer takes arguments. From the J4 potential backward compatibility page, https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4  
  > **username_0**: I will test this first chance I get  
  > **username_1**: could you test this already?  
  
  ---
  
  ### Answer by username_2 on 2024-04-22. Score: 0
  
  Have you tried using [CKeditor5](https://civicrm.org/extensions/ckeditor-5) or [summernote](https://civicrm.org/extensions/summernote) as a replacement got Kcfinder?
  
  > **Comments:**
  > **username_0**: Ckeditor is fine, but you lose the ability to browse for links  
  
  ---
  
  