I was wrong. Now I need Fred's help. I thought I could just do:
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if(is_plugin_active('w3-total-cache/w3-total-cache.php')){
include_once( ABSPATH . 'wp-content/plugins/w3-total-cache/lib/W3/Plugin/CdnCommon.php' );
...
}
However this isn't correct. I need to know where the black magic occurs so I can change the output from nextgen-gallery/xml/json.php. Thanks.