Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Overwrite the thumbnail size with a URL parameter
etc wrote:
Why not?
thumbsize=x10is as meaningless asthumbsize=10x.
Of course it is… but you can just do !strpos($size, 'x'), or if (strpos($size, 'x')) if you flip the inverted conditions around. If you want the variables to work independently, the easiest way without messy code is two parameters, too.
It being a single parameter, I would rather do what Gil first had. Its much cleaner, readable and gets the job done.
Last edited by Gocom (2013-10-09 19:31:29)
Offline
Offline
Re: Overwrite the thumbnail size with a URL parameter
Gocom wrote:
It being a single parameter, I would rather do what Gil first had. Its much cleaner, readable and gets the job done.
This would yield two queries (for thumb_w and thumb_h) even if there were only one parameter changed. For the rest, Gil should check if the values are not negative, and so on, but he’s a big boy. :)
Offline
Re: Overwrite the thumbnail size with a URL parameter
@Gil – yes please do submit this as a TXP Tip! Thanks!
Offline
Re: Overwrite the thumbnail size with a URL parameter
Hey Gil! Please, share it with us. I’m lost in PHP and plugin composer. ;)
Offline
Re: Overwrite the thumbnail size with a URL parameter
OK no tip this time, I made it better and now it’s a plugin with an admin UI, yeay!
Here’s my plugin code, I used the code for the UI from “ebl_image_edit” plugin.
Please check it and let me know if it good and safe to use, if it is then I will publish it.
In case and you find any problem in the code please let me know and if you can please provide a fix code since I don’t know SQL at all and just used a code from an other plugin to make it happen.
- The plugin will work together with “bot_image_upload” plugin, set it load order to 6, to run after it.
- The plugin let you set a thumbnail size base on each “bot_image_upload” button field ID, or base on section.
- Base on section overwrites the base on field which gives much more control.
- The plugin does not modify any code from “bot_image_upload” plugin, so there is no need to worry about it.
- Of course you don’t have to use “bot_image_upload” plugin for this, you can simply add the “thumbsize” parameter with a size value in the image tab manually or using an other plugin.
- I called it “gil_thumb_size” should I change the prefix to “ggs” or I can use “gil” even that it’s my first name only?
- Do you think “thumb_size” is a good name to go with, or you may got anything better to suggest for this one?
- I’m including both Jukka and Oleg in the author name together with mine, is it fine with you guys?
- The plugin creates a database table name “txp_gil_thumb_size” to save the sizes in it.
- There are 3 “register_callback“s:
- first one is for the gui
- second for the JS in the write tab to work with “bot_image_upload”
- and third for settings the thumbnail size in the image tab
if(@txpinterface == 'admin'){
add_privs('gil_thumb_size', '1');
register_tab('extensions', 'gil_thumb_size', 'Thumbnail Size');
register_callback('gil_thumb_size_gui', 'gil_thumb_size');
register_callback('gil_thumb_size_js','article');
register_callback('gil_thumb_size_php','image');
}
// Creates the gui
function gil_thumb_size_gui(){
$step = gps('step');
$message = (is_callable($step)) ? $step() : '';
echo pagetop('gil_thumb_size Preferences', $message).n.
gil_thumb_sizes();
}
// Set database table and gui list
function gil_thumb_sizes(){
if(!mysql_num_rows(mysql_query("SHOW TABLES LIKE 'txp_gil_thumb_size'"))==1){
$creatTable = safe_query("CREATE TABLE `".PFX."txp_gil_thumb_size` (".
"`name` varchar(64) NOT NULL,".
"`width` varchar(16) NOT NULL,".
"`height` varchar(16) NOT NULL,".
"`section` varchar(1) NOT NULL default '0',".
"UNIQUE KEY `name` (`name`)".
");");
// Insert example thumbnail size for article-image field
$rs = safe_insert('txp_gil_thumb_size', "`name` = 'article-image', `width` = '100',`height` = '100', `section` = '0'");
}
// Create H1 and table head
echo n.hed(gTxt('Thumbnail Sizes'), 1).
n.n.startTable('list','','txp-list').
n.'<thead>'.tr(
n.hCell('Field ID or Section name').
n.hCell(gTxt('width')).
n.hCell().
n.hCell(gTxt('height')).
n.hCell(gTxt('section')).
n.hCell(gTxt('delete'))
).'</thead>';
// Building the saved sizes as table rows
$rs = safe_rows_start('*', 'txp_gil_thumb_size', '1=1 ORDER BY `name`');
$out = '';
if($rs){
while($a = nextRow($rs)){
$isChecked = ($a['section'] == 1) ? 'yes' : 'no';
$out .= n.tr(
td( htmlspecialchars($a['name'])).
td( htmlspecialchars($a['width'])).
td( htmlspecialchars(' X ')).
td( htmlspecialchars($a['height'])).
td( $isChecked).
td( dLink('gil_thumb_size', 'gil_thumb_delete', 'sizename', $a['name']))
);
}
}
echo form($out);
// Create a form row for creating new sizes
echo n.tr(
form(
td( fInput('text', 'name', '', 'edit','','',20) ).
td( fInput('text', 'width', '', 'edit','','',5) ).
td( htmlspecialchars(' X ')).
td( fInput('text', 'height', '', 'edit','','',5) ).
td( '<input name="gts_section" class="checkbox" type="checkbox">').
td( fInput('submit', 'add', gTxt('add'), 'smallerbox') ).
n.eInput('gil_thumb_size').
n.sInput('gil_thumb_save')
)
);
echo n.endTable();
}
// Gets the saves sizes
function gil_thumb_select($section = '0'){
$rs = safe_rows_start('*', 'txp_gil_thumb_size', 'section='.$section.' ORDER BY `name`');
if($rs){
while($a = nextRow($rs)){
$width = $a['width'];
$height = $a['height'];
$name = $a['name'];
$out .= "case '".htmlspecialchars($name)."' : thumbnail = '".$width."x".$height."'; break;".n;
}
}
return $out;
}
// Save new sizes
function gil_thumb_save(){
extract(doSlash(psa(array('name','width','height','gts_section'))));
if($name && is_numeric($width) && is_numeric($height)){
$gts_section = ($gts_section == "on") ? 1 : 0;
$rs = @safe_insert('txp_gil_thumb_size', "
`name` = '$name',
`width` = '$width',
`height` = '$height',
`section` = '$gts_section'");
return ($rs) ?
'New thumb size created' :
'<b>Error:</b> Duplicate Name';
}else{
return '<b>Width</b> and <b>Height</b> must be numeric values';
}
return FALSE;
}
// Delete sizes
function gil_thumb_delete(){
$name = ps('sizename');
return (safe_delete('txp_gil_thumb_size', "`name` = '".doSlash($name)."'")) ?
"<b>Deleted</b> $name" :
"<b>Error</b> Unable to delete $name";
}
// Write tab javascript
function gil_thumb_size_js(){
$gts_fields = gil_thumb_select(0);
$gts_sections = gil_thumb_select(1);
echo "
<script>
$(document).ready(function(){
// Set the 'thumbsize' variable with default thumbnail size value
var thumbsize = '100x100';
// Set thumbnail size base on field ID
$('.bot_add_image').each(function(){
switch($(this).parents('p').find('input').attr('id')){
".$gts_fields."
}
$(this).parents('p').find('.bot_add_image').attr('data-thumbsize',thumbsize);
});
// Set thumbnail size base on section name
// This overwrites the previous settings which were base on field ID
$('#section').change(function(){
switch($(this).val()){
".$gts_sections."
}
$('.bot_add_image').attr('data-thumbsize',thumbsize);
}).change();
// Assign the thumbsize parameter with the value to bot_image_upload iframe
var check_for_bot_iu_iframe;
$('.bot_add_image').click(function(){
check_for_bot_iu_iframe = setInterval(function(){
if($('#bot_iu_iframe').length > 0){
$('#bot_iu_iframe').attr('src',$('#bot_iu_iframe').attr('src')+'&thumbsize='+thumbsize);
clearInterval(check_for_bot_iu_iframe);
}
},100);
});
});
</script>
";
}
// Images tab PHP
function gil_thumb_size_php(){
global $prefs;
$defaultSize = '100x100';
$currentSize = $prefs['thumb_w'].'x'.$prefs['thumb_h'];
$newSize = gps('thumbsize');
if(strpos($newSize,'x') && $newSize != $currentSize){
$newSize = explode('x',$newSize);
set_pref('thumb_w', (int) $newSize[0], 'image');
set_pref('thumb_h', (int) $newSize[1], 'image');
}else if(strpos($defaultSize,'x') && $currentSize != $defaultSize){
$defaultSize = explode('x',$defaultSize);
set_pref('thumb_w', (int) $defaultSize[0], 'image');
set_pref('thumb_h', (int) $defaultSize[1], 'image');
}
}
Offline
Re: Overwrite the thumbnail size with a URL parameter
BTW: the reason I toke the code out of the CLASS it is because I don’t know how to call the save and delete functions from the html buttons in these lines of code:
n.sInput('gil_thumb_save')
td( dLink('gil_thumb_size', 'gil_thumb_delete', 'sizename', $a['name']))
now it works because it is not OO in a CLASS, but if you can help me make it work in a class then I will wrap it all in it again.
Sorry I just don’t know the syntax, even that it’s fine like that without a class like most of the other plugins.
I must say that I have learned a lot, and it is a nice achievement for someone how don’t really know PHP, by using all your help of course.
(a lot of things are equals to JS which makes it more easy for me to understand)
Offline
Re: Overwrite the thumbnail size with a URL parameter
Some comments:
$message = (is_callable($step)) ? $step() : '';
Remote code execution vulnerability. Allows calling any function on the server. Step always must be verified using bouncer().
bq.
$step = gps('step');
There is no CSRF token check, see Textpattern’s form(), tInput(), form_token() and bouncer() functions. E.g.
$steps = array(
'save' => true,
'delete' => true,
));
if ($step && bouncer($step, $steps))
{
$message = $this->$step();
}
txp_
txp prefix is reserved by Textpattern core. Use your own, gil etc, instead.
mysql_num_rows(mysql_query(
Should use the DB layer Textpattern comes with. These will break if we stop using the deprecated classic MySQL extension. This also generates an additional notice if the query fails, since mysql_query will return FALSE, but mysql_num_rows expects a resource.
$out .= "case '".htmlspecialchars($name)."' : thumbnail = '".$width."x".$height."'; break;".n;
You have to sanitize the name for JavaScript, while now you are sanitizing it for HTML. Add an single quote to the name and the code breaks. Use escape_js() on variables and wrap the JavaScript block itself to script_js(), or you could just return JSON objects.
$out .=…return $out;
References undefined variable. Need to define it before you can reference it. Defining has to happen outside the condition.
SHOW TABLES LIKE 'txp_gil_thumb_size'
This fails if the database uses prefixes. Wrap table names to safe_pfx() when referencing a table in a query.
"`width` varchar(16) NOT NULL," "`height` varchar(16) NOT NULL,". "`section` varchar(1) NOT NULL default '0',".
All of these are integers; field should be integer too.
is_numeric($width) && is_numeric($height)
PHP’s is_numeric() doesn’t work for checking whether a variable is integer-like. You are better off type casting.
THE BLUE DRAGON wrote:
buttons in these lines of code:
You do it when you are calling the step method. E.g.
$this->$step();
Last edited by Gocom (2013-10-12 11:12:37)
Offline
#24 2013-10-12 13:17:18
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: Overwrite the thumbnail size with a URL parameter
Reserved gil as your developer prefix, Gil.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Overwrite the thumbnail size with a URL parameter
Thank you Jukka
and thanks Uli for the prefix.
Here’s the new code, have I done all the changes right?
(it is working)
One thing that I still don’t understand is:
I don’t know how to set a global variable of the database table name for use in SQL queries,
currently I’m setting it over and over again in each function which is stupid.
$gts_table = safe_pfx('gil_thumb_size');
what is the right syntax for setting a global variable outside the functions and use it inside them please?
BTW: I will also fix some issues that you have mentioned, in the ebl_image_edit plugin now that we are aware of them.
class gil_thumb_size{
// Constructor
public function __construct(){
if(@txpinterface == 'admin'){
add_privs('gil_thumb_size', '1');
register_tab('extensions', 'gil_thumb_size', 'Thumbnail Size');
register_callback(array($this, 'gil_thumb_size_gui'), 'gil_thumb_size');
register_callback(array($this, 'gil_thumb_size_js'), 'article');
register_callback(array($this, 'gil_thumb_size_php'), 'image');
}
}
// Creates the gui
public function gil_thumb_size_gui(){
$step = gps('step');
$title = 'gil_thumb_size Preferences';
$steps = array(
'gil_thumb_save' => true,
'gil_thumb_delete' => true
);
if($step && bouncer($step, $steps)){
$message = $this->$step();
$this->$step();
$ptop = pagetop($title, $message);
}else{
$ptop = pagetop($title);
}
echo $ptop.n.
$this->gil_thumb_sizes();
}
// Set database table and gui list
public function gil_thumb_sizes(){
$gts_table = safe_pfx('gil_thumb_size');
if(!numrows(safe_query("SHOW TABLES LIKE $gts_table"))==1){
$creatTable = safe_query("CREATE TABLE `".PFX."$gts_table` (".
"`name` varchar(64) NOT NULL,".
"`width` int(4) NOT NULL,".
"`height` int(4) NOT NULL,".
"`section` int(1) NOT NULL default '0',".
"UNIQUE KEY `name` (`name`)".
");");
}
// Create H1 and table head
echo n.hed(gTxt('Thumbnail Sizes'), 1).
n.n.startTable('list','','txp-list').
n.'<thead>'.tr(
n.hCell('Field ID or Section name').
n.hCell(gTxt('width')).
n.hCell().
n.hCell(gTxt('height')).
n.hCell(gTxt('section')).
n.hCell(gTxt('delete'))
).'</thead>';
// Building the saved sizes as table rows
$rs = safe_rows_start('*', $gts_table, '1=1 ORDER BY `name`');
$out = '';
if($rs){
while($a = nextRow($rs)){
$isChecked = ($a['section'] == 1) ? 'yes' : 'no';
$out .= n.tr(
td( htmlspecialchars($a['name'])).
td( htmlspecialchars($a['width'])).
td( htmlspecialchars(' X ')).
td( htmlspecialchars($a['height'])).
td( $isChecked).
td( dLink('gil_thumb_size', 'gil_thumb_delete', 'name', $a['name']))
);
}
}
echo form($out);
// Create a form row for creating new sizes
$gtb_save = $this->gil_thumb_save();
echo n.tr(
form(
td( fInput('text', 'name', '', 'edit','','',20) ).
td( fInput('text', 'width', '', 'edit','','',5) ).
td( htmlspecialchars(' X ')).
td( fInput('text', 'height', '', 'edit','','',5) ).
td( '<input name="gts_section" class="checkbox" type="checkbox">').
td( fInput('submit', 'add', gTxt('add'), 'smallerbox') ).
n.eInput('gil_thumb_size').
n.sInput('gil_thumb_save')
)
);
echo n.endTable();
}
// Gets the saves sizes
public function gil_thumb_select($section = '0'){
$gts_table = safe_pfx('gil_thumb_size');
$rs = safe_rows_start('*', $gts_table, 'section='.$section.' ORDER BY `name`');
$out = '';
if($rs){
while($a = nextRow($rs)){
$width = escape_js($a['width']);
$height = escape_js($a['height']);
$name = escape_js($a['name']);
$out .= "case '".$name."' : thumbnail = '".$width."x".$height."'; break;".n;
}
}
return $out;
}
// Save new sizes
public function gil_thumb_save(){
$gts_table = safe_pfx('gil_thumb_size');
extract(doSlash(psa(array('name','width','height','gts_section'))));
if($name && $width && $height){
$gts_section = ($gts_section == "on") ? 1 : 0;
$rs = @safe_insert($gts_table, "
`name` = '$name',
`width` = '$width',
`height` = '$height',
`section` = '$gts_section'");
return ($rs) ?
'New thumb size created' :
'<b>Error:</b> Duplicate Name';
}else{
return '<b>Width</b> and <b>Height</b> must be numeric values';
}
return FALSE;
}
// Delete sizes
public function gil_thumb_delete(){
$gts_table = safe_pfx('gil_thumb_size');
$name = ps('name');
return (safe_delete($gts_table, "`name` = '".doSlash($name)."'")) ?
"<b>Deleted</b> $name" :
"<b>Error</b> Unable to delete $name";
}
// Write tab javascript
public function gil_thumb_size_js(){
$gts_fields = $this->gil_thumb_select(0);
$gts_sections = $this->gil_thumb_select(1);
echo script_js("
$(document).ready(function(){
// Set the 'thumbsize' variable with default thumbnail size value
var thumbsize = '100x100';
// Set thumbnail size base on field ID
$('.bot_add_image').each(function(){
switch($(this).parents('p').find('input').attr('id')){
$gts_fields
}
$(this).parents('p').find('.bot_add_image').attr('data-thumbsize',thumbsize);
});
// Set thumbnail size base on section name
// This overwrites the previous settings which were base on field ID
$('#section').change(function(){
switch($(this).val()){
$gts_sections
}
$('.bot_add_image').attr('data-thumbsize',thumbsize);
}).change();
// Assign the thumbsize parameter with the value to bot_image_upload iframe
var check_for_bot_iu_iframe;
$('.bot_add_image').click(function(){
check_for_bot_iu_iframe = setInterval(function(){
if($('#bot_iu_iframe').length > 0){
$('#bot_iu_iframe').attr('src',$('#bot_iu_iframe').attr('src')+'&thumbsize='+thumbsize);
clearInterval(check_for_bot_iu_iframe);
}
},100);
});
});
");
}
// Images tab PHP
public function gil_thumb_size_php(){
global $prefs;
$defaultSize = '100x100';
$currentSize = $prefs['thumb_w'].'x'.$prefs['thumb_h'];
$newSize = gps('thumbsize');
if(strpos($newSize,'x') && $newSize != $currentSize){
$newSize = explode('x',$newSize);
set_pref('thumb_w', (int) $newSize[0], 'image');
set_pref('thumb_h', (int) $newSize[1], 'image');
}else if(strpos($defaultSize,'x') && $currentSize != $defaultSize){
$defaultSize = explode('x',$defaultSize);
set_pref('thumb_w', (int) $defaultSize[0], 'image');
set_pref('thumb_h', (int) $defaultSize[1], 'image');
}
}
}
$gtb = new gil_thumb_size;
Offline
Re: Overwrite the thumbnail size with a URL parameter
@Gil – would still be a great write up for TXP Tips if you have time – maybe on how to compose a plugin?
Offline
Re: Overwrite the thumbnail size with a URL parameter
THE BLUE DRAGON wrote:
I don’t know how to set a global variable of the database table name for use in SQL queries
You don’t use global variables. When using a class, you may use a property, but usage of global variables should always be avoided as it pollutes the global namespace. Global variables and the keyword are just PHP’s legacy features that predates actual namespaces. But. You don’t have to do what you are doing.
$rs = safe_rows_start('*', $gts_table, 'section='.$section.' ORDER BY `name`');
In queries itself, but not when there is dedicated table argument; these functions that have a table argument do prefixing for you (otherwise there wouldn’t be this limited argument syntax).
$message = $this->$step();$this->$step();
This runs the method twice.
"`section` int(1) NOT NULL default '0',".
That’s 4 bytes for single bit. TINYINT field will fit one bit just fine. Lowers storage requirement by marginal 3 bytes per row.
$width = escape_js($a['width']);$height = escape_js($a['height']);
These are always integers. If you really wanted to escape these, you would be casting them, but you don’t have to do anything.
$gtb = new gil_thumb_size;
That variable is unnecessary (and not prefixed).
public function gil_thumb_size_gui(){
You don’t have to prefix all methods if you don’t want to. They are not in global namespace.
// Constructor
There are differences between the few comment syntaxes, and we use different ones for reasons. The ones I had there are meant for documentation, and are interpreted by tokenizer differently from the rest, and used by tools such as PHPDoc, and IDEs to provide documentation.
Last edited by Gocom (2013-10-13 07:06:50)
Offline
Re: Overwrite the thumbnail size with a URL parameter
Thanks
- looks much better.
- fixed a bug in my JS, and added a conditional statement for checking if there are any “bot_image_upload” fields.
- combined the two UI functions into a single one, so now there are 6 main functions/methods which are:- ui (Creates the ui and steps, set database table and list size items)
- get (Gets the saved sizes)
- save (Save new sizes)
- delete (Delete sizes)
- js (Write tab javascript)
- set (Images tab PHP, gets the “thumbsize” parameter from the URL and set it values in the pref)
The new code with the changes:
class gil_thumb_size {
/**
* Constructor
*/
public function __construct(){
if(@txpinterface == 'admin'){
add_privs('gil_thumb_size', '1');
register_tab('extensions', 'gil_thumb_size', 'Thumbnail Size');
register_callback(array($this, 'ui'), 'gil_thumb_size');
register_callback(array($this, 'js'), 'article');
register_callback(array($this, 'set'), 'image');
}
}
/**
* Creates the ui and steps
*
* Set database table and list size items
*/
public function ui(){
$step = gps('step');
$steps = array('save' => true, 'delete' => true);
$title = 'gil_thumb_size Preferences';
$gts_table = safe_pfx('gil_thumb_size');
// Steps and message
if($step && bouncer($step, $steps)){
$message = $this->$step();
$ptop = pagetop($title, $message);
}else{
$ptop = pagetop($title);
}
echo $ptop;
// Create DB table
if(!numrows(safe_query("SHOW TABLES LIKE $gts_table"))==1){
$creatTable = safe_query("CREATE TABLE `".PFX."$gts_table` (".
"`name` VARCHAR(64) NOT NULL,".
"`width` INT(4) NOT NULL,".
"`height` INT(4) NOT NULL,".
"`section` TINYINT(1) NOT NULL default '0',".
"UNIQUE KEY `name` (`name`)".
");");
}
// Create H1 and table head
echo n.hed(gTxt('Thumbnail Sizes'), 1).
n.n.startTable('list','','txp-list').
n.'<thead>'.tr(
n.hCell('Field ID or Section name').
n.hCell(gTxt('width')).
n.hCell().
n.hCell(gTxt('height')).
n.hCell(gTxt('section')).
n.hCell(gTxt('delete'))
).'</thead>';
// Building the saved sizes as table rows
$rs = safe_rows_start('*', 'gil_thumb_size', '1=1 ORDER BY `name`');
$out = '';
if($rs){
while($a = nextRow($rs)){
$isChecked = ($a['section'] == 1) ? 'yes' : 'no';
$out .= n.tr(
td( htmlspecialchars($a['name'])).
td( htmlspecialchars($a['width'])).
td( htmlspecialchars(' X ')).
td( htmlspecialchars($a['height'])).
td( $isChecked).
td( dLink('gil_thumb_size', 'delete', 'name', $a['name']))
);
}
}
echo form($out);
// Create a form row for creating new sizes
$gtb_save = $this->save();
echo n.tr(
form(
td( fInput('text', 'name', '', 'edit','','',20) ).
td( fInput('text', 'width', '', 'edit','','',5) ).
td( htmlspecialchars(' X ')).
td( fInput('text', 'height', '', 'edit','','',5) ).
td( '<input name="gts_section" class="checkbox" type="checkbox">').
td( fInput('submit', 'add', gTxt('add'), 'smallerbox') ).
n.eInput('gil_thumb_size').
n.sInput('save')
)
);
echo n.endTable();
}
/**
* Gets the saved sizes
*/
public function get($section = '0'){
$rs = safe_rows_start('*', 'gil_thumb_size', 'section='.$section.' ORDER BY `name`');
$out = '';
if($rs){
while($a = nextRow($rs)){
$width = $a['width'];
$height = $a['height'];
$name = escape_js($a['name']);
$out .= "case '".$name."' : thumbsize = '".$width."x".$height."'; break;".n;
}
}
return $out;
}
/**
* Save new sizes
*/
public function save(){
extract(doSlash(psa(array('name','width','height','gts_section'))));
if($name && $width && $height){
$gts_section = ($gts_section == "on") ? 1 : 0;
$rs = @safe_insert('gil_thumb_size', "
`name` = '$name',
`width` = '$width',
`height` = '$height',
`section` = '$gts_section'");
return ($rs) ?
'New thumb size created' :
'<b>Error:</b> Duplicate Name';
}else{
return '<b>Width</b> and <b>Height</b> must be numeric values';
}
return FALSE;
}
/**
* Delete sizes
*/
public function delete(){
$name = ps('name');
return (safe_delete('gil_thumb_size', "`name` = '".doSlash($name)."'")) ?
"<b>Deleted</b> $name" :
"<b>Error</b> Unable to delete $name";
}
/**
* Write tab javascript
*/
public function js(){
$gts_by_fields = $this->get(0);
$gts_by_sections = $this->get(1);
echo script_js("
$(document).ready(function(){
// Set the 'thumbsize' variable
var thumbsize = '';
// Check if 'bot_image_upload' plugin fields exists
if($('.bot_add_image').length > 0){
// Set thumbnail size base on field ID
$('.bot_add_image').each(function(){
switch($(this).parents('p').find('input').attr('id')){
$gts_by_fields
}
$(this).parents('p').find('.bot_add_image').attr('data-thumbsize',thumbsize);
});
// Set thumbnail size base on section name
// This overwrites the previous settings which were base on field ID
$('#section').change(function(){
switch($(this).val()){
$gts_by_sections
}
$('.bot_add_image').attr('data-thumbsize',thumbsize);
}).change();
// Assign the thumbsize parameter with the value to bot_image_upload iframe
var check_for_bot_iu_iframe;
$('.bot_add_image').click(function(){
check_for_bot_iu_iframe = setInterval(function(){
if($('#bot_iu_iframe').length > 0){
$('#bot_iu_iframe').attr('src',$('#bot_iu_iframe').attr('src')+'&thumbsize='+thumbsize);
clearInterval(check_for_bot_iu_iframe);
}
},100);
});
}
});
");
}
/**
* Images tab PHP
*
* Gets the "thumbsize" parameter from the URL and set it values in the pref.
*/
public function set(){
global $prefs;
$defaultSize = '100x100';
$currentSize = $prefs['thumb_w'].'x'.$prefs['thumb_h'];
$newSize = gps('thumbsize');
if(strpos($newSize,'x') && $newSize != $currentSize){
$newSize = explode('x',$newSize);
set_pref('thumb_w', (int) $newSize[0], 'image');
set_pref('thumb_h', (int) $newSize[1], 'image');
}else if(strpos($defaultSize,'x') && $currentSize != $defaultSize){
$defaultSize = explode('x',$defaultSize);
set_pref('thumb_w', (int) $defaultSize[0], 'image');
set_pref('thumb_h', (int) $defaultSize[1], 'image');
}
}
}
new gil_thumb_size;
Edit oops posted an old code, now it’s the new.
Last edited by THE BLUE DRAGON (2013-10-13 10:57:01)
Offline
#29 2013-10-13 12:42:03
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: Overwrite the thumbnail size with a URL parameter
THE BLUE DRAGON wrote:
Gil, I’ve altered and improved that plugin enormously during the last few months:BTW: I will also fix some issues that you have mentioned, in the ebl_image_edit plugin now that we are aware of them.
- resizing & cropping in one go, hence all resizing/cropping/thumbnailing can happen in only one panel. Side effect: The cropping frame for creating the thumbnail can simply be reused for creating the final image.
- all of the above steps can be done even if the image is squished by a too small window
- individual rotation with the aid of an angle measurement tool
- individual sharpening
- individual lightening/darkening
- undo last step
- scrolls down to thumbnail on thumbnail creation
- plays nice with adi_image_tab: updates its dimension display
- massive help support via title tags
and would like to keep all changes (like yours and Marco’s png watermark) in one plugin file and of course publish the result. But I’ve not the level of coding skills that you’re discussing on here and needed at least a diff in order to follow what you’ve done.
Hence: Could you please keep one version of ebl_ie from immediately before these changes and after. I can, of course, offer you my version of the plugin to apply the alterations immediately there, but that’s only a proposal you don’t need to accept.
Last edited by uli (2013-10-13 17:46:39)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Overwrite the thumbnail size with a URL parameter
uli wrote:
Gil, I’ve altered and improved that plugin enormously over the last few months:
wow that’s sounds great!
will contact you about it probably next weekend or maybe sometime before :)
Offline