Skip to content
Snippets Groups Projects
Commit c8954e37 authored by Jan Grewe's avatar Jan Grewe
Browse files

initial commit

parents
Branches master
No related tags found
No related merge requests found
<?php
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
if (isset($_POST['submit'])) {
if(isset($_POST['cdn_enabled'])) {
$cdn_enabled = 'true';
}else{
$cdn_enabled = 'false';
}
$q = 'UPDATE '.CONFIG_TABLE.' SET value="'.$cdn_enabled.'" WHERE param="cdn_enabled"';
pwg_query($q);
$q = 'UPDATE '.CONFIG_TABLE.' SET value="'.$_POST['cdn_count'].'" WHERE param="cdn_count"';
pwg_query($q);
$q = 'UPDATE '.CONFIG_TABLE.' SET value="'.$_POST['cdn_host'].'" WHERE param="cdn_host"';
pwg_query($q);
list($conf['cdn_enabled']) = array_from_query('SELECT value FROM '.CONFIG_TABLE.' WHERE param = "cdn_enabled"', 'value');
list($conf['cdn_count']) = array_from_query('SELECT value FROM '.CONFIG_TABLE.' WHERE param = "cdn_count"', 'value');
list($conf['cdn_host']) = array_from_query('SELECT value FROM '.CONFIG_TABLE.' WHERE param = "cdn_host"', 'value');
}
$template->set_filename('plugin_admin_content', dirname(__FILE__).'/admin.tpl');
$template->assign(
array(
'CDN_ENABLED' => $conf['cdn_enabled'],
'CDN_COUNT' => $conf['cdn_count'],
'CDN_HOST' => $conf['cdn_host'],
)
);
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
?>
<div class="titlePage">
<h2>{'CDN'|@translate}</h2>
</div>
<form method="post" class="properties">
<fieldset>
<legend>{'CDN'|@translate}</legend>
<ul>
<li>
<label>
{'Enabled:'|@translate}
<input type="checkbox" name="cdn_enabled" value="true"{if $CDN_ENABLED} checked="checked"{/if}>
</label>
</li>
<li>
<label>
{'Host:'|@translate}
<input type="text" name="cdn_host"{if $CDN_HOST} value="{$CDN_HOST}"{/if}> (the # will be replaced with a number from 0 to &lt;count&gt;)
</label>
</li>
<li>
<label>
{'Count:'|@translate}
<input type="text" name="cdn_count"{if $CDN_COUNT} value="{$CDN_COUNT}"{/if}>
</label>
</li>
</ul>
</fieldset>
<p>
<input class="submit" type="submit" name="submit" value="{'Submit'|@translate}">
</p>
</form>
\ No newline at end of file
<?php
$url = '../';
header( 'Request-URI: '.$url );
header( 'Content-Location: '.$url );
header( 'Location: '.$url );
exit();
?>
<?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;
}
?>
\ No newline at end of file
<?php
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
class cdn_maintain extends PluginMaintain {
function install($plugin_version, &$errors=array()) {
$q = 'INSERT INTO '.CONFIG_TABLE.' (param, value, comment) VALUES ("cdn_host", "cdn#.example.com", "CDN host");';
pwg_query($q);
$q = 'INSERT INTO '.CONFIG_TABLE.' (param, value, comment) VALUES ("cdn_enabled", "false", "CDN enabled")';
pwg_query($q);
$q = 'INSERT INTO '.CONFIG_TABLE.' (param, value, comment) VALUES ("cdn_count", "3", "CDN host count")';
pwg_query($q);
}
function activate($plugin_version, &$errors=array()) {
}
function update($old_version, $new_version, &$errors=array()) {
}
function deactivate() {
}
function uninstall() {
$q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param LIKE "cdn_%";';
pwg_query($q);
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment