JomSocial was written to core and needs upgrade - php

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:
Separate the changes from the core files he made on 4.0.9.
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.

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()).

Related

How does WP file loading work? How does it work when used in WP MVC plugin?

I've created a video about one of the major problem that I have. I need to understand the file loading architecture, how it's done when writing a class in WP plugin development (how one class knows about the existence of another class), and how this compares with WP MVC file loading architecture. It's one big question, and I went through the various smaller questions that helped me arrived at the question summary in the video in the drive link below. I'm putting the plugin code in the Google Drive folder also: https://drive.google.com/open?id=1JVSSlkSJ5pCfNojRh6jen3ax2w-HZr5d
WP side:
plugin.php has this line: $wp_filter[ $tag ]->do_action( $args );
$tag = 'init'
This calls WP_Hook->do_action, then WP_Hook->apply_filters
WP MVC side:
This then calls MvcLoader->init, which then calls the needed load_controllers/libs/models/settings/functions (only the files under the bolded folder names will be loaded)
load_controllers will use the file_includer and make all files under the [plugin app path]/controllers be required
This means that any class under the specified folders above will be auto-required for the plugin that depends on WP MVC [tested]
This also explains why if one create a helper function, following the documentation, one would put the class under helper folder, but that doesn't get auto-loaded and one will get class not found error (because helpers doesn't get loaded/not in the list above)
Upon a closer inspection, it looks like only classes extending MvcController can load any helper files (base class MvcController is the only class that has load_helper() function). The helper files need to be named xyzHelper, under helpers folder, and needs to extend MvcHelper. In the child controller class, call $this->load_helper('xyz') and the base class will automatically try to load the helper class from the helpers folder. The controller class will now have a helper object named xyz (the class name, including underscores, without the _helper suffix). One can now have access to the helper class through the controller class (in the view classes also, etc. Used like $controller->xyz->function()) [tested]
How to get the above info:
Activate an example plugin from WP MVC and navigate to a public view
Put the breakpoint in mvc_file_includer.php require_file() [I actually just run the debugger without any breakpoint and there was a deprecated function warning at the above function. I didn't think to put a breakpoint at that function previous to seeing this, and I didn't know where to put the breakpoints previous to this realization]
Look at the stack trace and try to understand
Also, in WP MVC, there are other calls that will automatically include files
An example is render_view() - This will either call the controller's, or the helper's, render_view(), which will use the file_includer to find the desired file path, and call require on that file path. Therefore, it's more like this is a dynamic-loading of files that is being used.
Now, how did MvcLoader->init() get triggered?
In the main plugin's file: wp_mvc.php, depending on if it's in the admin/public functionality view, wp_mvc_load_global_functionality is called with the needed parameter. One of the actions in that function is add_action('init', array($loader, 'init')), which triggers the init hook for the MvcAdminLoader, which is a child of MvcLoader [tested by commenting out the add_action and it no longer works]

Where can I put my global code in Kohana 3.3?

Say I want a constant, a function or a class to be available in all my models, views and controllers code (within a particular web site (application)). Where can I put them? I don't mind importing them explicitly in every file I need them in but I don't know how (simple require_once does not seem to work).
You can put them in the vendor folder (in application/vendor or modules/MOD/vendor). Then you can load it like this:
require Kohana::find_file('vendor', 'folder/file','ext');
You can read up more on this in the user guide
Now, it should be stated you should in general not use functions or globals.
I declare Constants in Bootstrap.php and create my own Helpers for general functions under application/classes/Helpers.
If you need to integrate a third party library into Kohana or want to make code available to other Kohana users consider creating a module instead.
You can define all your constants in new php file and place it in the application/classes directory. In your Template controller or in the main controller like Welcome or Website, just place the code in the __constructor()
require_once Kohana::find_file( 'classes', 'filename' );
I suggest you to put your constant variables in the bootstrap.php file because this is loaded by the framework before every request.
You can simply put your classes in the root of the classes directory, the framework will find.
This worked well for me...
In application/config/constants.php:
define('SOME_COOL_CONSTANT', 'foo');
return array();
In index.php:
Kohana::$config->load('constants');
SOME_COOL_CONSTANT should then be available globally.

prestashop 1.5 core file overwrite

I want to overwrite prestashop 1.5 core file FrontController.php to overwrite from override\classes\controller folder but it didn't load my overwrite folder file.
<?php
class FrontController extends FrontControllerCore
{
/* Display a specific page if the user country is not allowed */
protected function displayRestrictedCountryPage() {
}
}
Any body have idea how to over write core prestashop file in 1.5
I also follow this document but no way to solve.
Prestashop 1.5.x automatically merge default override file and you custom file on module::install() function. You just need to create a correct hierarchy in your module folder: modules/your_package/override/classes/controller/FrontController.php with your custom functional.
If you don't have an extension and want to add override manually - you need to change the file override/classes/controller/FrontController.php
Just remove the class_index.php under /cache folder.
It carries Presta's Class & Controller file details. Once you delete and reload the page, prestashop will automatically generate the file with latest changes.
The problem may be, that one of your functions which contains parent::nameOfFunction, You should replace parent in the function by the inheritance of the parent function you want to override.
The function you're trying to override is called in the core function init(). what you should do is to override both init() and displayRestrictedCountryPage(). Then inside the init function use Controller::init() instead of parent::init()
After override whatever you want don"t forget to delete the cache folder contents and recreate them because that lost my time for a while till found the solution here

Can I extend the codeigniter core system, to use my custom functions on multiple sites?

I am currently using CodeIgniter to support one site, whose main purpose is to display multiple editable tablekit tables, and handle the AJAX that arrives when you edit them. A kind of PHPMyAdmin [VERY] Lite. It has a number of core helpers and controllers, which run the main workings of the site, mixed in with some site specific controllers and helpers.
I would like to restructure my site so that I can reuse the core code-base in another site. However, I would still like to be have some default controller functions and some cutsom functions in the same controller; i.e. in a system file somewhere:
class My_core extends Controller{
/*
Lots of base functions
*/
}
and on one site:
class site_1 extends My_Core{
/*
Site specific functions
*/
}
Then on the other site:
class site_2 extends My_Core{
/*
Site specific functions
*/
}
Does anyone have any guidance on how I can do this?
Thanks,
Lemiant
If you are using CodeIgniter 2.0 you can achieve most of this with with packages. They will let you load helpers, libraries and models from anywhere, so in each application simply configure a package to be loaded from that shared folder.
As for core libraries (which MY_Controller will be) you will have to implement your own __autoload() function:
http://php.net/manual/en/language.oop5.autoload.php
You can put an autoloader at the bottom of config.php. As long as it is checking the correct folders (local first, then the shared folder structure) it should all work pretty nicely.
I don't know if this is still helpful to you but heres what I've done.
say I have 2 websites, palladium.com and osmium.com.
my file tree looks like this
/var/www/system/ (the CI system folder)
/var/www/palladium/application
/var/www/palladium/public/index.php
/var/www/osmium/application
/var/www/osmium/public/index.php
inside those index.php files are lines that define where /system/ is stored. I've got that set to
$system_folder = "../../system";
Now inside /var/www/system/libraries i have a file named MY_TestClass
<?php
class MY_TestClass {
public function MY_TestClass() {
echo "this is a test of the emergency broadcast system";
}
}
From anywhere inside BOTH palladium.com and osmium.com i can call
$this->load->library('MY_TestClass');
and "this is a test of the emergency broadcast system" will show up.

Adding 3rd party library to ZendFramework

my question is simple:
How do I add an API and/or 3rd party
library to my ZendFramework
application in a way which makes it
possible to access it in a
controller
Here is a blog post detailing how to achieve this: http://blog.keppens.biz/2009/05/add-your-own-library-to-your-new-zend.html
Alternatively, if you don't want to tweak the application.ini file, you can do it through your Bootstrap class. Add this function to Bootstrap:
protected function _initAutoload() {
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MyCode_');
}
Then in the "library" folder, you would add a folder called "MyCode". This folder should be parallel to the "Zend" folder. Naturally you should change "MyCode" to reflect the name of the library you're adding.
I should note that by using the above method, I'm assuming the code uses the PEAR naming scheme (just like ZF).

Categories