What it does
An AdvertisementLocations extension allows you to define locations and settings for advertisements in order to allow you to insert advertisements in specific locations within your application. The forums application uses this, for example, to allow advertisements to be shown after the first post in a topic and in the topic listing.
How to use
When you create a new instance of this application extension, you will need to define two methods (which will already be defined via a template if you use the Developer Center to create the extension).
/**
* Get the locations and the additional settings
*
* @param array $settings Current setting values
* @return array Array with two elements: 'locations' which should have keys as the location keys and values as the fields to toggle, and 'settings' which are additional fields to add to the form
*/
public function getSettings( $settings )
The getSettings method accepts one parameter (an array) and should return an array with two elements. The first, with key 'locations', should be an array with its keys being the advertisement location keys you are defining, and the values being an array of setting keys to use for the location. The second element should use a key 'settings' and define an array of form helper objects to return. For example:
/**
* Get the locations and the additional settings
*
* @param array $settings Current setting values
* @return array Array with two elements: 'locations' which should have keys as the location keys and values as the fields to toggle, and 'settings' which are additional fields to add to the form
*/
public function getSettings( $settings )
{
return array(
'locations' => array( 'ad_fluid_index_view' => array( 'ad_fluid_index_view_number', 'ad_fluid_index_view_repeat' ) ),
'settings' => array(
new \IPS\Helpers\Form\Number( 'ad_fluid_index_view_number', ( isset( $settings['ad_fluid_index_view_number'] ) ) ? $settings['ad_fluid_index_view_number'] : 0, FALSE, array(), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('ad_fluid_index_view_number_suffix'), 'ad_fluid_index_view_number' ),
new \IPS\Helpers\Form\Number( 'ad_fluid_index_view_repeat', ( isset( $settings['ad_fluid_index_view_repeat'] ) ) ? $settings['ad_fluid_index_view_repeat'] : 0, FALSE, array( 'unlimited' => -1 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('ad_fluid_index_view_repeat_suffix'), 'ad_fluid_index_view_repeat' )
)
);
}
The second method in this file is parseSettings(), which is a callback allowing you to adjust the setting values that are stored during an administrator's submission. If there are no settings, this method should just return an empty array.
/**
* Return an array of setting values to store
*
* @param array $values Values from the form submission
* @return array Array of setting key => value to store
*/
public function parseSettings( $values )
{
return array(
'ad_fluid_index_view_number' => $values['ad_fluid_index_view_number'],
'ad_fluid_index_view_repeat' => $values['ad_fluid_index_view_repeat']
);
}
You can then use the advertisement in your output with the loadByLocation method of \IPS\core\Advertisement. For instance:
{{if $advertisement = \IPS\core\Advertisement::loadByLocation( 'ad_fluid_index_view' )}}
{$advertisement|raw}
{{endif}}
Report Document