Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\admin\promotion;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -22,6 +22,16 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _advertisements extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Active tab
|
||||
*/
|
||||
protected $activeTab = '';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -30,22 +40,96 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'advertisements_manage' );
|
||||
|
||||
/* Get tab content */
|
||||
$this->activeTab = \IPS\Request::i()->tab ?: 'site';
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Work out output */
|
||||
$thisUrl = \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' );
|
||||
$activeTabContents = (string) static::table( $thisUrl, ( $this->activeTab == 'emails' ) );
|
||||
|
||||
/* If this is an AJAX request, just return it */
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Action Buttons */
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
'title' => 'ad_settings',
|
||||
'icon' => 'cog',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=settings' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('ad_settings') )
|
||||
);
|
||||
|
||||
/* If Nexus is not installed, show message */
|
||||
if( !\IPS\Application::appIsEnabled( 'nexus' ) AND !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'promotion' )->advertisementMessage( );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'promotion/advertisements.css', 'core', 'admin' ) );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('advertisements');
|
||||
|
||||
/* Build tab list */
|
||||
$tabs = array( 'site' => 'advertisements_site', 'emails' => 'advertisements_emails' );
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->tabs( $tabs, $this->activeTab, $activeTabContents, $thisUrl );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table
|
||||
*
|
||||
* @param \IPS\Http\Url $url The URL the table will be shown on
|
||||
* @param bool $email Email advertisements (true) or website (false)
|
||||
* @return void
|
||||
*/
|
||||
public static function table( \IPS\Http\Url $url, $email=FALSE )
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_advertisements', \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' ) );
|
||||
$where = NULL;
|
||||
|
||||
if( $email === TRUE )
|
||||
{
|
||||
$where = array( array( 'ad_type=?', \IPS\core\Advertisement::AD_EMAIL ) );
|
||||
$url = $url->setQueryString( 'tab', 'emails' );
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['ads_ad_impressions'] = \IPS\Member::loggedIn()->language()->addToStack('ads_ad_sends');
|
||||
}
|
||||
else
|
||||
{
|
||||
$where = array( array( 'ad_type!=?', \IPS\core\Advertisement::AD_EMAIL ) );
|
||||
$url = $url->setQueryString( 'tab', 'site' );
|
||||
}
|
||||
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_advertisements', $url, $where );
|
||||
$table->langPrefix = 'ads_';
|
||||
|
||||
/* Columns we need */
|
||||
$table->include = array( 'word_custom', 'ad_html', 'ad_impressions', 'ad_clicks', 'ad_active' );
|
||||
$table->include = array( 'word_custom', 'ad_html', 'ad_impressions' );
|
||||
|
||||
if( $email === TRUE )
|
||||
{
|
||||
$table->include[] = 'ad_email_views';
|
||||
$table->include[] = 'ad_clicks';
|
||||
$table->include[] = 'ad_active';
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->include[] = 'ad_clicks';
|
||||
$table->include[] = 'ad_active';
|
||||
}
|
||||
$table->mainColumn = 'word_custom';
|
||||
$table->noSort = array( 'ad_images', 'ad_html' );
|
||||
$table->joins = array(
|
||||
@@ -67,12 +151,12 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
|
||||
/* Filters */
|
||||
$table->filters = array(
|
||||
'ad_filters_active' => array('ad_active=1 AND ( ad_end=0 OR ad_end > ? )', time() ),
|
||||
'ad_filters_inactive' => array('ad_active=0 OR ad_end<? ', time() ),
|
||||
'ad_filters_active' => array( 'ad_active=1 AND ( ad_end=0 OR ad_end > ? )', time() ),
|
||||
'ad_filters_inactive' => array( '(ad_active=0 OR (ad_end>0 AND ad_end<?))', time() ),
|
||||
);
|
||||
|
||||
/* If Nexus is installed, we get the pending filter too */
|
||||
if( \IPS\Application::appIsEnabled( 'nexus' ) )
|
||||
if( \IPS\Application::appIsEnabled( 'nexus' ) AND $email === FALSE )
|
||||
{
|
||||
$table->filters['ad_filters_pending'] = 'ad_active=-1';
|
||||
}
|
||||
@@ -85,7 +169,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
},
|
||||
'ad_html' => function( $val, $row )
|
||||
{
|
||||
if( $row['ad_html'] )
|
||||
if( $row['ad_type'] == \IPS\core\Advertisement::AD_HTML )
|
||||
{
|
||||
$preview = \IPS\Theme::i()->getTemplate( 'promotion' )->advertisementIframePreview( $row['ad_id'] );
|
||||
}
|
||||
@@ -93,7 +177,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$advert = \IPS\core\Advertisement::constructFromData( $row );
|
||||
|
||||
if( !count( $advert->_images ) )
|
||||
if( !\count( $advert->_images ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -110,17 +194,26 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
'ad_clicks' => function( $val, $row )
|
||||
{
|
||||
return $row['ad_html'] ? \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( 'unavailable', array( 'ipsType_light' ) ) : $val;
|
||||
}
|
||||
},
|
||||
'ad_impressions' => function( $val, $row )
|
||||
{
|
||||
return $val;
|
||||
},
|
||||
'ad_email_views' => function( $val, $row )
|
||||
{
|
||||
return \intval( $val );
|
||||
},
|
||||
);
|
||||
|
||||
/* Specify the buttons */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_add' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['add'] = array(
|
||||
'primary' => TRUE,
|
||||
'icon' => 'plus',
|
||||
'title' => 'add',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=form' )
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'icon' => 'plus',
|
||||
'title' => 'add',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=form&type=' . ( ( $email === TRUE ) ? 'emails' : 'site' ) )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,7 +228,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
$return['approve'] = array(
|
||||
'icon' => 'check',
|
||||
'title' => 'approve',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=toggle&status=1&id=' . $row['ad_id'] ),
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=toggle&status=1&id=' . $row['ad_id'] )->csrf(),
|
||||
'hotkey' => 'a',
|
||||
);
|
||||
}
|
||||
@@ -161,24 +254,8 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
return $return;
|
||||
};
|
||||
|
||||
/* Action Buttons */
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
'title' => 'ad_settings',
|
||||
'icon' => 'cog',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=settings' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('ad_settings') )
|
||||
);
|
||||
|
||||
/* If Nexus is not installed, show message */
|
||||
if( !\IPS\Application::appIsEnabled( 'nexus' ) AND !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'promotion' )->advertisementMessage( );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'promotion/advertisements.css', 'core', 'admin' ) );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('advertisements');
|
||||
\IPS\Output::i()->output .= (string) $table;
|
||||
/* Return */
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,6 +328,8 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
protected function toggle()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Get our record */
|
||||
try
|
||||
{
|
||||
@@ -308,6 +387,16 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
try
|
||||
{
|
||||
$record = \IPS\core\Advertisement::load( \IPS\Request::i()->id );
|
||||
|
||||
if( $record->type == \IPS\core\Advertisement::AD_EMAIL )
|
||||
{
|
||||
\IPS\Request::i()->type = 'emails';
|
||||
\IPS\Member::loggedIn()->language()->words['ad_impressions'] = \IPS\Member::loggedIn()->language()->addToStack('ad_sends_so_far');
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Request::i()->type = 'site';
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -325,80 +414,134 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
/* Start the form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'ad_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( !$record->id ) ? NULL : "core_advert_{$record->id}" ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'ad_type', ( $record->id ) ? ( $record->html ? 'html' : 'image' ) : 'html', TRUE, array( 'options' => array( 'html' => 'ad_type_html', 'image' => 'ad_type_image' ), 'toggles' => array( 'html' => array( 'ad_html', 'ad_html_specify_https', 'ad_maximums_html' ), 'image' => array( 'ad_url', 'ad_new_window', 'ad_image', 'ad_image_more', 'ad_clicks', 'ad_maximums_image' ) ) ), NULL, NULL, NULL, 'ad_type' ) );
|
||||
|
||||
/* Show the fields for an HTML advertisement */
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'ad_html', ( $record->id ) ? $record->html : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_html' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_html_specify_https', ( $record->id ) ? $record->html_https_set : FALSE, FALSE, array( 'togglesOn' => array( 'ad_html_https' ) ), NULL, NULL, NULL, 'ad_html_specify_https' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'ad_html_https', ( $record->id ) ? $record->html_https : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_html_https' ) );
|
||||
if( \IPS\Request::i()->type != 'emails' )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'ad_type', ( $record->id ) ? $record->type : \IPS\core\Advertisement::AD_HTML, TRUE, array( 'options' => array( 1 => 'ad_type_html', 2 => 'ad_type_image' ), 'toggles' => array( \IPS\core\Advertisement::AD_HTML => array( 'ad_html', 'ad_html_specify_https', 'ad_maximums_html', 'ad_location', 'ad_exempt' ), \IPS\core\Advertisement::AD_IMAGES => array( 'ad_url', 'ad_image_alt', 'ad_new_window', 'ad_image', 'ad_image_more', 'ad_clicks', 'ad_maximums_image', 'ad_location', 'ad_exempt' ) ) ), NULL, NULL, NULL, 'ad_type' ) );
|
||||
|
||||
/* Show the fields for an image advertisement */
|
||||
/* Show the fields for an HTML advertisement */
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'ad_html', ( $record->id ) ? $record->html : NULL, NULL, array(), function( $val ) {
|
||||
if( \IPS\Request::i()->ad_type == 1 AND !$val ) {
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, NULL, 'ad_html' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_html_specify_https', ( $record->id ) ? $record->html_https_set : FALSE, FALSE, array( 'togglesOn' => array( 'ad_html_https' ) ), NULL, NULL, NULL, 'ad_html_specify_https' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'ad_html_https', ( $record->id ) ? $record->html_https : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_html_https' ) );
|
||||
}
|
||||
|
||||
/* Show the fields for an image advertisement (and most of the email ad settings as well) */
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'ad_url', ( $record->id ) ? $record->link : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_url' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_new_window', ( $record->id ) ? $record->new_window : FALSE, FALSE, array(), NULL, NULL, NULL, 'ad_new_window' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image', ( $record->id ) ? ( ( isset( $record->_images['large'] ) and $record->_images['large'] ) ? \IPS\File::get( 'core_Advertisements', $record->_images['large'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_image_more', ( $record->id ) ? ( ( ( isset( $record->_images['medium'] ) and $record->_images['medium'] ) OR ( ( isset( $record->_images['small'] ) and $record->_images['small'] ) ) ) ? TRUE : FALSE ) : FALSE, FALSE, array( 'togglesOn' => array( 'ad_image_small', 'ad_image_medium' ) ), NULL, NULL, NULL, 'ad_image_more' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image_small', ( $record->id ) ? ( ( isset( $record->_images['small'] ) and $record->_images['small'] ) ? \IPS\File::get( 'core_Advertisements', $record->_images['small'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image_small' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image_medium', ( $record->id ) ? ( ( isset( $record->_images['medium'] ) and $record->_images['medium'] ) ? \IPS\File::get( 'core_Advertisements', $record->_images['medium'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image_medium' ) );
|
||||
|
||||
/* Add the location fields, remember to call extensions for additional locations.
|
||||
Array format: location => array of toggle fields to show */
|
||||
$defaultLocations = array(
|
||||
'ad_global_header' => array(),
|
||||
'ad_global_footer' => array(),
|
||||
'ad_sidebar' => array(),
|
||||
);
|
||||
|
||||
$currentValues = ( $record->id ) ? json_decode( $record->additional_settings, TRUE ) : array();
|
||||
|
||||
/* Now grab ad location extensions */
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
|
||||
if( \IPS\Request::i()->type != 'emails' )
|
||||
{
|
||||
$result = $extension->getSettings( $currentValues );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_new_window', ( $record->id ) ? $record->new_window : FALSE, FALSE, array(), NULL, NULL, NULL, 'ad_new_window' ) );
|
||||
}
|
||||
|
||||
$defaultLocations = array_merge( $defaultLocations, $result['locations'] );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image', ( $record->id ) ? ( ( isset( $record->_images['large'] ) and $record->_images['large'] ) ? \IPS\File::get( 'core_Advertisements', $record->_images['large'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image' ) );
|
||||
|
||||
if( isset( $result['settings'] ) )
|
||||
if( \IPS\Request::i()->type != 'emails' )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_image_more', ( $record->id ) ? ( ( ( isset( $record->_images['medium'] ) and $record->_images['medium'] ) OR ( ( isset( $record->_images['small'] ) and $record->_images['small'] ) ) ) ? TRUE : FALSE ) : FALSE, FALSE, array( 'togglesOn' => array( 'ad_image_small', 'ad_image_medium' ) ), NULL, NULL, NULL, 'ad_image_more' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image_small', ( $record->id ) ? ( ( isset( $record->_images['small'] ) and $record->_images['small'] ) ? \IPS\File::get( 'core_Advertisements', $record->_images['small'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image_small' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image_medium', ( $record->id ) ? ( ( isset( $record->_images['medium'] ) and $record->_images['medium'] ) ? \IPS\File::get( 'core_Advertisements', $record->_images['medium'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image_medium' ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ad_image_alt', ( $record->id ) ? $record->image_alt : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_image_alt' ) );
|
||||
|
||||
if( \IPS\Request::i()->type != 'emails' )
|
||||
{
|
||||
/* Add the location fields, remember to call extensions for additional locations.
|
||||
Array format: location => array of toggle fields to show */
|
||||
$defaultLocations = array(
|
||||
'ad_global_header' => array(),
|
||||
'ad_global_footer' => array(),
|
||||
'ad_sidebar' => array(),
|
||||
);
|
||||
|
||||
$currentValues = ( $record->id ) ? json_decode( $record->additional_settings, TRUE ) : array();
|
||||
|
||||
/* Now grab ad location extensions */
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
|
||||
{
|
||||
foreach( $result['settings'] as $setting )
|
||||
$result = $extension->getSettings( $currentValues );
|
||||
|
||||
$defaultLocations = array_merge( $defaultLocations, $result['locations'] );
|
||||
|
||||
if( isset( $result['settings'] ) )
|
||||
{
|
||||
$form->add( $setting );
|
||||
foreach( $result['settings'] as $setting )
|
||||
{
|
||||
$form->add( $setting );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$defaultLocations['_ad_custom_'] = array('ad_location_custom');
|
||||
|
||||
/* Add the locations to the form, and make sure the toggles get set properly */
|
||||
$locations = array();
|
||||
$customLocations = array();
|
||||
if ( $record->id )
|
||||
{
|
||||
$locations = explode( ',', $record->location );
|
||||
$customLocations = array_diff( $locations, array_keys( $defaultLocations ) );
|
||||
if ( !empty( $customLocations ) )
|
||||
{
|
||||
$locations[] = '_ad_custom_';
|
||||
}
|
||||
$locations = array_intersect( $locations, array_keys( $defaultLocations ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'ad_location',
|
||||
$locations,
|
||||
TRUE,
|
||||
array(
|
||||
'options' => array_combine( array_keys( $defaultLocations ), array_keys( $defaultLocations ) ),
|
||||
'toggles' => $defaultLocations,
|
||||
),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'ad_location'
|
||||
) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'ad_location_custom', $customLocations, FALSE, array(), NULL, NULL, NULL, 'ad_location_custom' ) );
|
||||
|
||||
/* Generic fields available for both html and image ads */
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'ad_exempt', ( $record->id ) ? ( ( $record->exempt == '*' ) ? '*' : json_decode( $record->exempt, TRUE ) ) : '*', FALSE, array( 'options' => \IPS\Member\Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone' ), NULL, NULL, NULL, 'ad_exempt' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_nocontent_page_output', ( $record->id ) ? $record->nocontent_page_output : FALSE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Container restrictions for email ads */
|
||||
$containerClasses = array();
|
||||
$containerToggles = array();
|
||||
|
||||
foreach( \IPS\Content::routedClasses( FALSE, FALSE, TRUE ) as $contentItemClass )
|
||||
{
|
||||
if( isset( $contentItemClass::$containerNodeClass ) AND $contentItemClass::$containerNodeClass AND !isset( $containerClasses[ $contentItemClass::$containerNodeClass ] ) )
|
||||
{
|
||||
$containerClass = $contentItemClass::$containerNodeClass;
|
||||
|
||||
$containerClasses[ $containerClass ] = $contentItemClass::$title . '_pl';
|
||||
$containerToggles[ $containerClass ] = array( 'node_' . md5( $containerClass ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( \count( $containerClasses ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Select( '_ad_email_container', ( $record->id AND isset( $record->_additional_settings['email_container'] ) ) ? $record->_additional_settings['email_container'] : '*', FALSE, array( 'options' => $containerClasses, 'multiple' => FALSE, 'unlimited' => '*', 'unlimitedLang' => 'unrestricted', 'toggles' => $containerToggles ), NULL, NULL, NULL, '_ad_email_container' ) );
|
||||
|
||||
foreach( $containerClasses as $classname => $lang )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'node_' . md5( $classname ), ( $record->id ) ? ( isset( $record->_additional_settings['email_node'] ) ? $record->_additional_settings['email_node'] : 0 ) : 0, FALSE, array( 'class' => $classname, 'zeroVal' => 'any', 'multiple' => TRUE, 'forceOwner' => FALSE ), NULL, NULL, NULL, 'node_' . md5( $classname ) ) );
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words[ 'node_' . md5( $classname ) ] = \IPS\Member::loggedIn()->language()->addToStack( $classname::$nodeTitle );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$defaultLocations['_ad_custom_'] = array('ad_location_custom');
|
||||
|
||||
/* Add the locations to the form, and make sure the toggles get set properly */
|
||||
$locations = array();
|
||||
$customLocations = array();
|
||||
if ( $record->id )
|
||||
{
|
||||
$locations = explode( ',', $record->location );
|
||||
$customLocations = array_diff( $locations, array_keys( $defaultLocations ) );
|
||||
if ( !empty( $customLocations ) )
|
||||
{
|
||||
$locations[] = '_ad_custom_';
|
||||
}
|
||||
$locations = array_intersect( $locations, array_keys( $defaultLocations ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'ad_location',
|
||||
$locations,
|
||||
TRUE,
|
||||
array(
|
||||
'options' => array_combine( array_keys( $defaultLocations ), array_keys( $defaultLocations ) ),
|
||||
'toggles' => $defaultLocations,
|
||||
),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'ad_location'
|
||||
) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'ad_location_custom', $customLocations, FALSE, array(), NULL, NULL, NULL, 'ad_location_custom' ) );
|
||||
|
||||
/* Generic fields universally available for both types of ads */
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'ad_exempt', ( $record->id ) ? ( ( $record->exempt == '*' ) ? '*' : json_decode( $record->exempt, TRUE ) ) : '*', FALSE, array( 'options' => \IPS\Member\Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone' ) ) );
|
||||
/* Generic fields for all ad types */
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'ad_start', ( $record->id ) ? \IPS\DateTime::ts( $record->start ) : new \IPS\DateTime, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'ad_end', ( $record->id ) ? ( $record->end ? \IPS\DateTime::ts( $record->end ) : 0 ) : 0, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'indefinitely' ) ) );
|
||||
|
||||
@@ -407,10 +550,19 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'ad_impressions', ( $record->id ) ? $record->impressions : 0, FALSE, array(), NULL, NULL, NULL, 'ad_impressions' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'ad_clicks', ( $record->id ) ? $record->clicks : 0, FALSE, array(), NULL, NULL, NULL, 'ad_clicks' ) );
|
||||
|
||||
if( \IPS\Request::i()->type == 'emails' )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'ad_email_views', ( $record->id ) ? $record->email_views : 0, FALSE, array(), NULL, NULL, NULL, 'ad_email_views' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Click/impression maximum cutoffs, toggled depending upon HTML or image type ad */
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'ad_maximums_html', ( $record->id ) ? $record->maximum_value : -1, FALSE, array( 'unlimited' => -1 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('ad_max_impressions'), 'ad_maximums_html' ) );
|
||||
if( \IPS\Request::i()->type != 'emails' )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'ad_maximums_html', ( $record->id ) ? $record->maximum_value : -1, FALSE, array( 'unlimited' => -1 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('ad_max_impressions'), 'ad_maximums_html' ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'ad_maximums_image', array( 'value' => ( $record->id ) ? $record->maximum_value : -1, 'type' => ( $record->id ) ? $record->maximum_unit : 'i' ), FALSE, array(
|
||||
'getHtml' => function( $element )
|
||||
{
|
||||
@@ -418,7 +570,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
},
|
||||
'formatValue' => function( $element )
|
||||
{
|
||||
if( !is_array( $element->value ) AND $element->value == -1 )
|
||||
if( !\is_array( $element->value ) AND $element->value == -1 )
|
||||
{
|
||||
return array( 'value' => -1, 'type' => 'i' );
|
||||
}
|
||||
@@ -430,36 +582,48 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$locations = $values['ad_location'];
|
||||
$customKey = array_search( '_ad_custom_', $locations );
|
||||
if ( $customKey !== FALSE )
|
||||
if( \IPS\Request::i()->type != 'emails' )
|
||||
{
|
||||
unset( $locations[ $customKey ] );
|
||||
$locations = array_merge( $locations, $values['ad_location_custom'] );
|
||||
$locations = $values['ad_location'];
|
||||
$customKey = array_search( '_ad_custom_', $locations );
|
||||
if ( $customKey !== FALSE )
|
||||
{
|
||||
unset( $locations[ $customKey ] );
|
||||
$locations = array_merge( $locations, $values['ad_location_custom'] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$locations = array();
|
||||
$values['ad_type'] = \IPS\core\Advertisement::AD_EMAIL;
|
||||
}
|
||||
|
||||
/* Let us start with the easy stuff... */
|
||||
$record->type = $values['ad_type'];
|
||||
$record->location = implode( ',', $locations );
|
||||
$record->html = ( $values['ad_type'] == 'html' ) ? $values['ad_html'] : NULL;
|
||||
$record->link = ( $values['ad_type'] == 'image' ) ? $values['ad_url'] : NULL;
|
||||
$record->new_window = ( $values['ad_type'] == 'image' ) ? $values['ad_new_window'] : 0;
|
||||
$record->html = ( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML ) ? $values['ad_html'] : NULL;
|
||||
$record->link = ( $values['ad_type'] != \IPS\core\Advertisement::AD_HTML ) ? $values['ad_url'] : NULL;
|
||||
$record->image_alt = ( $values['ad_type'] != \IPS\core\Advertisement::AD_HTML ) ? $values['ad_image_alt'] : NULL;
|
||||
$record->new_window = ( $values['ad_type'] == \IPS\core\Advertisement::AD_IMAGES ) ? $values['ad_new_window'] : 0;
|
||||
$record->impressions = ( isset( $values['ad_impressions'] ) ) ? $values['ad_impressions'] : 0;
|
||||
$record->clicks = ( $values['ad_type'] == 'image' AND isset( $values['ad_clicks'] ) ) ? $values['ad_clicks'] : 0;
|
||||
$record->clicks = ( $values['ad_type'] != \IPS\core\Advertisement::AD_HTML AND isset( $values['ad_clicks'] ) ) ? $values['ad_clicks'] : 0;
|
||||
$record->email_views = ( $values['ad_type'] == \IPS\core\Advertisement::AD_EMAIL AND isset( $values['ad_email_views'] ) ) ? $values['ad_email_views'] : NULL;
|
||||
$record->active = ( $record->id ) ? $record->active : 1;
|
||||
$record->html_https = ( $values['ad_type'] == 'html' ) ? $values['ad_html_https'] : NULL;
|
||||
$record->html_https = ( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML ) ? $values['ad_html_https'] : NULL;
|
||||
$record->start = $values['ad_start'] ? $values['ad_start']->getTimestamp() : 0;
|
||||
$record->end = $values['ad_end'] ? $values['ad_end']->getTimestamp() : 0;
|
||||
$record->exempt = ( $values['ad_exempt'] == '*' ) ? '*' : json_encode( $values['ad_exempt'] );
|
||||
$record->exempt = ( $values['ad_type'] != \IPS\core\Advertisement::AD_EMAIL ) ? ( $values['ad_exempt'] == '*' ) ? '*' : json_encode( $values['ad_exempt'] ) : NULL;
|
||||
$record->images = NULL;
|
||||
$record->maximum_value = ( $values['ad_type'] == 'html' ) ? $values['ad_maximums_html'] : $values['ad_maximums_image']['value'];
|
||||
$record->maximum_unit = ( $values['ad_type'] == 'html' ) ? 'i' : $values['ad_maximums_image']['type'];
|
||||
$record->maximum_value = ( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML ) ? $values['ad_maximums_html'] : $values['ad_maximums_image']['value'];
|
||||
$record->maximum_unit = ( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML ) ? 'i' : $values['ad_maximums_image']['type'];
|
||||
$record->additional_settings = NULL;
|
||||
$record->html_https_set = ( $values['ad_type'] == 'html' ) ? $values['ad_html_specify_https'] : 0;
|
||||
$record->html_https_set = ( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML ) ? $values['ad_html_specify_https'] : 0;
|
||||
$record->nocontent_page_output = isset( $values['ad_nocontent_page_output'] ) ? $values['ad_nocontent_page_output'] : FALSE;
|
||||
|
||||
/* Figure out the ad_images */
|
||||
$images = array();
|
||||
|
||||
if( $values['ad_type'] == 'image' )
|
||||
if( $values['ad_type'] == \IPS\core\Advertisement::AD_IMAGES )
|
||||
{
|
||||
$images = array( 'large' => (string) $values['ad_image'] );
|
||||
|
||||
@@ -484,7 +648,22 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
$values['ad_image_medium']->delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
elseif( $values['ad_type'] == \IPS\core\Advertisement::AD_EMAIL )
|
||||
{
|
||||
$images = array( 'large' => (string) $values['ad_image'] );
|
||||
|
||||
/* Make sure we don't retain any small/medium copies if they switched to images then to email */
|
||||
if( isset( $values['ad_image_small'] ) AND $values['ad_image_small'] )
|
||||
{
|
||||
$values['ad_image_small']->delete();
|
||||
}
|
||||
|
||||
if( isset( $values['ad_image_medium'] ) AND $values['ad_image_medium'] )
|
||||
{
|
||||
$values['ad_image_medium']->delete();
|
||||
}
|
||||
}
|
||||
elseif( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML )
|
||||
{
|
||||
/* Did they upload images and then switch back to an html type ad, by chance? */
|
||||
if( isset( $values['ad_image'] ) AND $values['ad_image'] )
|
||||
@@ -503,10 +682,13 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
/* If we are editing, and we changed from image -> html, clean up old images */
|
||||
if( $record->id AND count( $record->_images ) AND $values['ad_type'] == 'html' )
|
||||
/* If we are editing, and we changed from image/email -> html/email, clean up old images */
|
||||
if( $record->id AND \count( $record->_images ) AND ( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML OR $values['ad_type'] == \IPS\core\Advertisement::AD_EMAIL ) )
|
||||
{
|
||||
\IPS\File::get( 'core_Advertisements', $record->_images['large'] )->delete();
|
||||
if( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML )
|
||||
{
|
||||
\IPS\File::get( 'core_Advertisements', $record->_images['large'] )->delete();
|
||||
}
|
||||
|
||||
if( isset( $record->_images['small'] ) )
|
||||
{
|
||||
@@ -524,11 +706,19 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
/* Any additional settings to save? */
|
||||
$additionalSettings = array();
|
||||
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
|
||||
if( $values['ad_type'] == \IPS\core\Advertisement::AD_EMAIL )
|
||||
{
|
||||
$settings = $extension->parseSettings( $values );
|
||||
$additionalSettings['email_container'] = $values['_ad_email_container'];
|
||||
$additionalSettings['email_node'] = ( $values['_ad_email_container'] != '*' ) ? ( ( $values['node_' . md5( $values['_ad_email_container'] ) ] == 0 ) ? 0 : array_keys( $values['node_' . md5( $values['_ad_email_container'] ) ] ) ) : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
|
||||
{
|
||||
$settings = $extension->parseSettings( $values );
|
||||
|
||||
$additionalSettings = array_merge( $additionalSettings, $settings );
|
||||
$additionalSettings = array_merge( $additionalSettings, $settings );
|
||||
}
|
||||
}
|
||||
|
||||
$record->additional_settings = json_encode( $additionalSettings );
|
||||
@@ -545,7 +735,8 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
$record->save();
|
||||
|
||||
/* Save if any exist */
|
||||
$adsExist = (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_advertisements', 'ad_active=1' )->first();
|
||||
$adsExist = $record->active ? TRUE : (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_advertisements', 'ad_active=1' )->first();
|
||||
|
||||
if ( $adsExist != \IPS\Settings::i()->ads_exist )
|
||||
{
|
||||
\IPS\Settings::i()->changeValues( array( 'ads_exist' => $adsExist ) );
|
||||
@@ -558,7 +749,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
\IPS\Lang::saveCustom( 'core', 'core_advert_' . $record->id, $values[ 'ad_title' ] );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' ), 'saved' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&tab=' . \IPS\Request::i()->type ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( ( !isset( \IPS\Request::i()->id ) ) ? 'add_advertisement' : 'edit_advertisement' );
|
||||
@@ -589,6 +780,8 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
\IPS\Output::i()->error( 'node_error', '2C157/7', 404, '' );
|
||||
}
|
||||
|
||||
$preview = '';
|
||||
|
||||
if( $record->html )
|
||||
{
|
||||
if( \IPS\Request::i()->isSecure() AND $record->html_https_set )
|
||||
@@ -600,11 +793,6 @@ class _advertisements extends \IPS\Dispatcher\Controller
|
||||
$preview = $record->html;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$advert = \IPS\core\Advertisement::constructFromData( $record );
|
||||
$preview = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->advertisementImage( $advert );
|
||||
}
|
||||
|
||||
$preview = preg_replace( "/<script(?:[^>]*?)?>.*<\/script>/ims", \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( 'ad_script_disabled', array( 'ipsType_light' ) ), $preview );
|
||||
|
||||
|
||||
Reference in new issue
Block a user