Select Git revision
main.inc.php
main.inc.php 1.47 KiB
<?php
/*
Version: 0.1
Plugin Name: CDN
Plugin URI: // Here comes a link to the Piwigo extension gallery, after
// publication of your plugin. For auto-updates of the plugin.
Author: Jan Grewe <jan@faked.org>
Description: Set a different host to use as a CDN/Caching Proxy
*/
// Add an entry to the 'Plugins' menu.
add_event_handler('get_admin_plugin_menu_links', 'cdn_admin_menu');
function cdn_admin_menu($menu) {
global $page,$conf;
if ($conf['cdn_enabled'] == 'true' && empty($conf['cdn_host']) and in_array($page['page'], array('intro','plugins_list'))) {
$page['errors'][] = l10n('You need to set your CDN host');
}
$admin_url = get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php');
array_push($menu, array(
'NAME' => 'CDN',
'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php'
)
);
return $menu;
}
add_event_handler('get_derivative_url', 'cdn_add_prefix');
add_event_handler('get_src_image_url', 'cdn_add_prefix');
function cdn_add_prefix($content) {
global $conf;
if ($conf['cdn_enabled'] == 'true') {
$cdnHost = str_replace('#', rand(0, $conf['cdn_count']-1), $conf['cdn_host']);
$cdnUrl = 'http://'.$cdnHost.'/'.$_SERVER['SERVER_NAME'].make_index_url();
if(substr($content, 0, 5) == '_data') {
$content = $cdnUrl.$content;
}elseif(substr($content, 0, 5) == 'i.php') {
$content = $cdnUrl.$content;
}elseif(substr($content, 0, 11) == './galleries') {
$content = $cdnUrl.substr($content, 2);
}
}
return $content;
}
?>