Jump to content

You should probably perk up the saveCustom() language method


Go to solution Solved by bfarber,

Recommended Posts

Posted
/**
 * Save translatable language strings
 *
 * @param  string|int|\IPS\Application|\IPS\Plugin       $appOrPlugin   Application key or Plugin ID

So alright, string or int. For plugins hitting the settings method or the uninstall routines will give us the plugin_id via the request var.

\IPS\Lang::saveCustom(  \IPS\Request::i()->id, 'muh_word', $values['muh_word_setting'] );

If you do that, you're setting things up for a bad time down the road. That will set both the word_app AND word_plugin entries, together, to the plugin_id value instead of NULL, plugin_id respectively.


				if ( $appOrPlugin instanceof \IPS\Application )
				{
					$appOrPlugin = $appOrPlugin->directory;
				}
				elseif ( $appOrPlugin instanceof \IPS\Plugin )
				{
					$appOrPlugin = $appOrPlugin->_id;
				}
				
				$insert = array(
					'lang_id'		=> $langId,
					'word_app'		=> ( \is_string( $appOrPlugin ) ) ? $appOrPlugin : NULL,
					'word_plugin'	=> ( \is_numeric( $appOrPlugin ) ) ? $appOrPlugin : NULL,
					'word_key'		=> $key,
					'word_default'	=> $default,
					'word_custom'	=> $value,
					'word_js'		=> $js,
					'word_export'	=> FALSE,
					'word_is_custom'=> ( $isCustom === TRUE )
				);

If you were to throw instances at this method you are probably alright, but your use of is_string and is_numeric is problematic when passing through "numerals" as that request var, passed through settings as is, will evaluate true on both of those.

\IPS\Lang::saveCustom( (int) \IPS\Request::i()->id, 'muh_word', $values['muh_word_setting'] );

Explicitly casting to INT will save you here for those you coding custom language bits with plugins right now. If you already are in the wild with a plugin and you are using the request entry raw, your end users probably have some possibly problematic lang table entries. No idea what (anything?) can happen down the road with both app and plugin entries set.

You might want to bulletproof this a little more or require instances explicitly.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...