Announcement

  •  » Engine
  •  » [resolved] conf_update_param

#1 2014-06-03 11:38:58

rvelices
Former Piwigo Team
2005-12-29
1960

[resolved] conf_update_param

Hello,

On trunk we have

Code:

function conf_update_param($param, $value, $updateGlobal=false, $parser=null)
{
  if ($parser != null)
  {
    $dbValue = call_user_func($parser, $value);
  }
...

the problem I have is that if value is an array or object, parser cannot be set to 'addslashes(serialize)'

Could we have an easier function:

Code:

function conf_update_param($param, $value, $parser=null)
{
  $dbValue = $value;
  if ($value==='true')
    $value = true;
  elseif ($value==='false')
    $value = false;
  elseif (is_array($value) || is _object($value))
    $dbValue = addslashes(serialize($value));
  elseif ($parser != null)
    $dbValue = call_user_func($parser, $value);
... and always set global $conf ...

?

Obviously some changes are required if we decide to set the global once for all ... If we are to be beacward compatible, we can have for 2.7 only

Code:

function conf_update_param($param, $value, $parser=null, $updateGlobal=false)

and then just remove $updateGlobal  ...

What do you think ?

Offline

 

#2 2014-06-03 13:19:54

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: [resolved] conf_update_param

$parser can be set to a Closure or the result of create_function, or even a pointer to a class method
isn't it enough ?

personnally I never use addslashes after serialize, never had issues

--

anyway i don't get why you want/need to always update $conf...

Offline

 

#3 2014-06-03 15:01:40

rvelices
Former Piwigo Team
2005-12-29
1960

Re: [resolved] conf_update_param

mistic100 wrote:

$parser can be set to a Closure or the result of create_function, or even a pointer to a class method
isn't it enough ?

obviously writing

Code:

conf_update_param('x', $val, true, function ($x) { return addslashes(serialize($x)); } )

is always a possibility that nobody will use...

mistic100 wrote:

personnally I never use addslashes after serialize, never had issues

is when your arary contains strings with ' or \

mistic100 wrote:

anyway i don't get why you want/need to always update $conf...

I don't but why is it there then ?

Offline

 

#4 2014-06-03 15:17:50

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: [resolved] conf_update_param

rvelices wrote:

is always a possibility that nobody will use...

why not ? it's clear that if nobody starts to make Closures useful nobody will use them (of it's fetched :) )

rvelices wrote:

is when your arary contains strings with ' or \

totally right (has issue with ContactForm recently)

rvelices wrote:

I don't but why is it there then ?

Because it's useful :)
I added it as an option, totally optional, your version make it mandatory, which will break thinks when people do

Code:

conf_update_param("key", serialize($value));
// 2.6 : $value is an array
// 2.7 : $value is a string

edit: $conf['key'] is modified, not $value (I am doing Java with pointers everyday so I mess up !)
--

what I don't like in your version is that it doesn't let the choice of "encoding" (I now prefer JSON to serialize)

what about this

Code:

function conf_update_param($param, $value, $updateGlobal=false, $parser=null)
{
  if ($parser != null)
  {
    $dbValue = call_user_func($parser, $value);
  }
  else if (is_array($value) || is_object($value))
  {
    $dbValue = addslashes(serialize($value));
  }
  else
  {
    $dbValue = $value;
  }

....

serialize only if no parser is defined

Offline

 

#5 2014-06-03 15:23:29

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: [resolved] conf_update_param

I precise that the aim of the modification was to add $updateGlobal, and $parser became a need
not the reverse

Offline

 

#6 2014-06-03 15:54:32

rvelices
Former Piwigo Team
2005-12-29
1960

Re: [resolved] conf_update_param

I like better your last version.
Speaking of json I believe that you also have to add slashes after encoding ( you cant just use 'json_encode' as parser if you have strings that may contain apostrophes quotes or antislashes)

Offline

 

#7 2014-06-03 17:05:41

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: [resolved] conf_update_param

yes of course

Offline

 
  •  » Engine
  •  » [resolved] conf_update_param

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact