Search code examples
phpjoomlajomsocial

JomSocial was written to core and needs upgrade


I'm taking over a project where the original developer customized JomSocial and wrote directly to:

components/com_community/templates/jomsocial/layouts

And created there folders aswell as wrote into files like base.php and so on.

The current customized version of JomSocial is 4.0.9 and I need to update to the latest - 4.4.5, the Joomla version is - 3.8.1

I understand I need to create an override folder in my template folder like that for an example of the base.php file for each of the changes:

/templates/yourTemplateName/html/com_community/layouts/frontpage/base.php

But in order to keep the changes the developer made and have the latest version of JomSocial while not hindering further updates like in this situation I would have to if I'm not mistaken:

  1. Separate the changes from the core files he made on 4.0.9.

  2. Create folders and files in my templates folder for each core files I need to customize and have them include only the changes the developer made with an updated version of 4.4.5.

Am I getting this right? is there another way to do it? any help would be greatly appreciated.


Solution

  • You're correct on how to override the layout files in a template. Unfortunately it ties your overrides to a particular template - installing a different template and setting it as default will lose your overrides.

    You can override any other file in a component by using a plugin and intercepting the call to the component's controller, substituting your own. You would have to copy all of the Jomsocial files between the entry point (controller) and the file you want to apply changes to with this approach, which is probably why the original developer just overwrote the core component files directly (can't safely update with this approach anyway, without checking for changes to the code you've copied from the core component files into your override). This approach would look something like:

    class plgSystemComSocialOverride extends JPlugin {
    
           public function __construct(&$subject, $config = array()) {
              parent::__construct($subject, $config);
          }
    
          public function onAfterRoute() {
              $app = JFactory::getApplication();
              if('com_social' == JRequest::getCMD('option') && !$app->isSite()) {
                  require_once(dirname(__FILE__) . DS . 'comsocialoverride' . DS . 'my_jomsocial_controller.php');
              }
          }
     }
    

    I think you could combine the above approach with manipulating Joomla's class loader, to avoid having to directly copy Jomsocial files in order to change their include statements to your override files. In this approach, you'd override the controller as above and call the Jomsocial controller from that overridden controller. But before you do that, you'd add your overridden base.php or whatever to the class loader. I'm not sure if the new version of Jomsocial is using autoloading or not (i.e. import() instead of include()).