Quantcast
Channel: WordPress.org Forums » [W3 Total Cache] Support
Viewing all articles
Browse latest Browse all 19282

David Bitton on "[Plugin: W3 Total Cache] Trying to Add CDN Support to Nextgen Gallery Slideshow"

$
0
0

I have some success. This is now what the render_output() function looks like in nextgen-gallery/xml/json.php.

function render_output() {
		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' );

			$w3_plugin_cdncommon = new W3_Plugin_CdnCommon;
			$cdn = $w3_plugin_cdncommon->get_cdn();

			if($cdn){
				foreach($this->result['images'] as $image) {
					$path = $image->imageURL;
					$remote_path = $w3_plugin_cdncommon->uri_to_cdn_uri($path);
					$url_path = ltrim(parse_url($remote_path, PHP_URL_PATH), '/');
					$cdn_url = $cdn->format_url($url_path);
					$image->imageURL = $cdn_url;
				}
			}
		}

		if ($this->format == 'json') {

			header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
			$this->output = json_encode($this->result);
		} else {
			header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
			$this->output  = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n";
			$this->output .= "<nextgen-gallery>" . $this->create_xml_array( $this->result )  . "</nextgen-gallery>\n";
		}

	}

It's not perfect and would probably break if it wasn't used on my specific site. Please comment. Thanks!


Viewing all articles
Browse latest Browse all 19282

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>