Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Plugin activation/deactivation depending on selected theme  (Read 5992 times)

0 Members and 1 Guest are viewing this topic.

paquets

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 59
Plugin activation/deactivation depending on selected theme
« on: November 28, 2008, 06:27:01 pm »

Hi,

I'm a coppermine newbie so please bare with me. I was wondering if there is any way to deactivate all plugins on a CPG installation when a specific theme is selected. This while the plugins remain active with other themes.

Is that possible at all?

Thanks!
Logged

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Re: Plugin activation/deactivation depending on selected theme
« Reply #1 on: November 29, 2008, 07:02:10 pm »

If you're willing to add a hack, then it's possible.  It's not possible otherwise (not possible by modifying the themes or adding another plugin).  You can modify a plugin to look for a particular theme before implementing certain functions.  I have done that in a plugin I use on my family site.  But changing all the plugins you use is not feasible and makes it very difficult for upgrades.

The hack would actually be fairly simple I think (unless I'm ignoring some side effects).   Look for the following lines in include/init.inc.php:
Code: [Select]
// Include plugin API
require('include/plugin_api.inc.php');
if ($CONFIG['enable_plugins'] == 1) {
        CPGPluginAPI::load();
}
This loads all the activated plugins.  So to disable this for certain themes, add in checks on $CONFIG['theme'] for the admin-set theme or $USER['theme'] for the user-set theme.  So to disable the plugins for theme 'snowy_day', do something like this:
Code: [Select]
if (($CONFIG['enable_plugins'] == 1) && ($USER['theme'] != 'snowy_day')) {
        CPGPluginAPI::load();
}

But there's one major problem you have to address.  $CONFIG['theme'] and $USER['theme'] are not set until later on in init.inc.php.  So you would have to move or replicate this code.  I haven't looked into this yet and don't have time right now, so decide if you want a hack first and then you'll have to see if you can move the plugin loading code down below where $USER['theme'] is set.

I would add a comment in or make a list somewhere of hacks so that when you upgrade Coppermine, you can apply the hack to the new version.  (You have to do this unless you use the SVN repository for upgrades.)
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Plugin activation/deactivation depending on selected theme
« Reply #2 on: November 29, 2008, 10:30:10 pm »

I suggest you explain why you want this to be done - your initial request appears to be strange. Explain what you're actually trying to accomplish or what you have issues with - maybe we could suggest an altogether different solution that you haven't been thinking of yet.
Logged

paquets

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 59
Re: Plugin activation/deactivation depending on selected theme
« Reply #3 on: November 30, 2008, 04:00:57 pm »

Thanks Paver and Joachim,

The reason I'm asking for this is for implementing CuMin (an iPhone-friendly theme) on a Coppermine installation. In trying it, I noticed that plugins came in the way of letting that theme work properly. For instance, I had "Add thumbnails to Lightbox v1.2.3" installed and it conflicted with the theme. I disabled it and the theme worked fine thereafter. Since plugins are great, but bring extra weight and complexity to a Coppermine installation, my thinking is that for the iPhone, it would be better to have a lighter version of the same site, just for viewing, not adding comments, notes, etc... Now, I don't know if this is feasible at all. ???

That said, and if it's possible to do, to be able to remove plugins in specific sites could be useful not just for mobile platforms, thus having this request as a separate forum thread...

I've tried what Paver suggested but it did not work. Unfortunately I'm not enough of a coder to figure it out by myself. I tried moving and also adding the code further down in the include/init.inc.php file and it didn't work either.

Any ideas?

Thanks!
Logged

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Re: Plugin activation/deactivation depending on selected theme
« Reply #4 on: December 01, 2008, 12:10:18 am »

That's a good example of a reason to disable plugins for a particular theme: the "Add thumbnails to Lightbox" plugin implements a theme function that if the theme uses, you get an error.  This plugin tries to avoid filtering the page which has its own issues (assuming a certain output from the theme engine and being very CPU-intensive in some cases).

So the non-hack way of getting what you want is to remove this plugin completely and then modify your CuMin theme to remove links to the comments, etc. that you don't want to show up.

To hack what you want, start from the original include/init.inc.php.  If you're not sure what the original is, download a new copy of the CPG package, unzip it to a temporary directory, then copy the include/init.inc.php to your webserver overwriting the one there.

Then replace these lines:
Code: [Select]
// Include plugin API
require('include/plugin_api.inc.php');
if ($CONFIG['enable_plugins'] == 1) {
        CPGPluginAPI::load();
}
with these lines:
Code: [Select]
// Include plugin API
require('include/plugin_api.inc.php');
// HACK BEGIN - need to copy and apply to upgraded installations
// original lines
/*
if ($CONFIG['enable_plugins'] == 1) {
        CPGPluginAPI::load();
}
*/
// new lines
user_get_profile();
if (!empty($_GET['theme'])) {
    $USER['theme'] = $_GET['theme'];
}
$hack_theme_noplugins = 'fruity';
$hack_load_plugins = (($USER['theme'] != $hack_theme_noplugins) && ($CONFIG['theme'] != $hack_theme_noplugins)) ;
if (($CONFIG['enable_plugins'] == 1) && $hack_load_plugins) {
        CPGPluginAPI::load();
}
// to remove this hack, uncomment the original lines and comment/remove the new lines
// HACK END
In the replaced lines, replace 'fruity' in the variable $hack_theme_noplugins with your theme to disable plugins.

You can see I added some comments in the hacked lines so you can remove the hack or apply it to future upgrades.
Logged

paquets

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 59
Re: Plugin activation/deactivation depending on selected theme
« Reply #5 on: December 01, 2008, 08:37:18 pm »

It works like a charm.

Thanks a lot Paver!
Logged
Pages: [1]   Go Up
 

Page created in 0.021 seconds with 19 queries.