Jump to content

[BUG 4.7.17] A widget extending "\IPS\Content\Widget" always adds the tags field


Recommended Posts

I have a widget that extends the \IPS\Content\Widget class, and while my Content Item class doesn't implement/support tags, the widget option is still showing the field.

 

The issue is this code in /system/Content/Widget.php on lines 224-242:

		/* Tags */
		if( \IPS\Settings::i()->tags_enabled )
		{
			if ( \IPS\Settings::i()->tags_force_lower )
			{
				$options['autocomplete']['forceLower'] = TRUE;
			}

			if ( \IPS\Settings::i()->tags_clean )
			{
				$options['autocomplete']['filterProfanity'] = TRUE;
			}

			$options['autocomplete']['prefix'] = FALSE;
			$options['autocomplete']['minimized'] = FALSE;

			$return['tags'] = new \IPS\Helpers\Form\Text( 'widget_feed_tags', ( isset( $this->configuration['widget_feed_tags'] ) ? $this->configuration['widget_feed_tags'] : array( 'tags' => NULL ) ), FALSE, $options );

		}

 

For tags, the only check done is if the tags system is enabled. Other fields instead check properly also if the class implements the proper interface. This is the check for hiding content for example:

if ( \in_array( 'IPS\Content\Hideable', class_implements( $class ) ) )

 

Before adding the field, the code must also check if the \IPS\Content\Tags class is implemented.

Link to comment
Share on other sites

Another issue I found with the same application is that the widget throws an error about the allocated memory not being sufficient because the code assumes all applications have an updated column and defaults to it when the widget is not setup yet (lines 479-487)::

		$items = iterator_to_array( $class::getItemsWithPermission(
			$where,	/* Where clause */
			( isset( $this->configuration['widget_feed_sort_on'] ) and isset( $this->configuration['widget_feed_sort_dir'] ) ) ? ( ( $this->configuration['widget_feed_sort_on'] == '_rand' ) ? $this->configuration['widget_feed_sort_on'] : (  $class::$databaseTable . '.' . $class::$databasePrefix . $this->configuration['widget_feed_sort_on'] . ' ' . $this->configuration['widget_feed_sort_dir'] ) ) : ( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['updated'] . ' DESC' ), /* Order */

			( isset( $this->configuration['widget_feed_show'] ) AND $this->configuration['widget_feed_show'] ) ? $this->configuration['widget_feed_show'] : 5, /* Limit */
			( $skipPerms ) ? NULL : 'read', /* Permission key to check against */
			$hidden, /* Whether or not to include hidden items */
			$class::SELECT_IDS_FIRST
		) );

 

The problem is this code:

( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['updated'] . ' DESC' )

if no updated column is present in the map, everything stops working.

 

Debugging widgets is not exactly easy with that memory errors being thrown everywhere and anywhere. I managed to track it down in the end, and I fixed the issue in my application by manually setting a default value when none is present:

		# If we don't have a default sort order set one, the code falls back to the updated column which is not available in this application
		if ( !isset($this->configuration['widget_feed_sort_on']) )
		{
			$this->configuration['widget_feed_sort_on'] = 'added';
		}
		
		if ( !isset($this->configuration['widget_feed_sort_dir']) )
		{
			$this->configuration['widget_feed_sort_dir'] = 'DESC';
		}

 

Link to comment
Share on other sites

Thank you for bringing this issue to our attention! I can confirm this should be further reviewed and I have logged an internal bug report for our development team to investigate and address as necessary, in a future maintenance release.

 

Link to comment
Share on other sites

  • 4 weeks later...
  • Recently Browsing   0 members

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