Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -11,38 +11,83 @@
namespace IPS\core\modules\admin\promotion;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use IPS\Application;
use IPS\Content;
use IPS\core\Advertisement;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Extensions\AdvertisementLocationsAbstract;
use IPS\File;
use IPS\Helpers\Form;
use IPS\Helpers\Form\CheckboxSet;
use IPS\Helpers\Form\Codemirror;
use IPS\Helpers\Form\Custom;
use IPS\Helpers\Form\Date;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Form\Text;
use IPS\Helpers\Form\TextArea;
use IPS\Helpers\Form\Translatable;
use IPS\Helpers\Form\Upload;
use IPS\Helpers\Form\Url as FormUrl;
use IPS\Helpers\Form\YesNo;
use IPS\Helpers\Table\Db as TableDb;
use IPS\Http\Url;
use IPS\Lang;
use IPS\Member;
use IPS\Member\Group;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use function count;
use function defined;
use function intval;
use function is_array;
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
use const IPS\Helpers\Table\SEARCH_NUMERIC;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Advertisements
*/
class _advertisements extends \IPS\Dispatcher\Controller
class advertisements extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* @brief Active tab
*/
protected $activeTab = '';
protected string $activeTab = '';
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advertisements_manage' );
Dispatcher::i()->checkAcpPermission( 'advertisements_manage' );
/* Get tab content */
$this->activeTab = \IPS\Request::i()->tab ?: 'site';
$this->activeTab = Request::i()->tab ?: 'site';
parent::execute();
}
@@ -52,68 +97,67 @@ class _advertisements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* Work out output */
$thisUrl = \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' );
$activeTabContents = (string) static::table( $thisUrl, ( $this->activeTab == 'emails' ) );
$thisUrl = Url::internal( 'app=core&module=promotion&controller=advertisements' );
$activeTabContents = static::table( $thisUrl, ( $this->activeTab == 'emails' ) );
/* If this is an AJAX request, just return it */
if( \IPS\Request::i()->isAjax() )
if( Request::i()->isAjax() )
{
\IPS\Output::i()->output = $activeTabContents;
Output::i()->output = $activeTabContents;
return;
}
/* Action Buttons */
\IPS\Output::i()->sidebar['actions']['settings'] = array(
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') )
'link' => Url::internal( 'app=core&module=promotion&controller=advertisements&do=settings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('ad_settings') )
);
/* If Nexus is not installed, show message */
if( !\IPS\Application::appIsEnabled( 'nexus' ) AND !\IPS\Request::i()->isAjax() )
if( !Application::appIsEnabled( 'nexus' ) AND !Request::i()->isAjax() )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'promotion' )->advertisementMessage( );
Output::i()->output = 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');
Output::i()->title = 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 );
Output::i()->output .= 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 Url $url The URL the table will be shown on
* @param bool $email Email advertisements (true) or website (false)
* @return void
* @return TableDb
*/
public static function table( \IPS\Http\Url $url, $email=FALSE )
public static function table( Url $url, bool $email=FALSE ) : TableDb
{
/* Create the table */
$where = NULL;
if( $email === TRUE )
{
$where = array( array( 'ad_type=?', \IPS\core\Advertisement::AD_EMAIL ) );
$where = array( array( 'ad_type=?', Advertisement::AD_EMAIL ) );
$url = $url->setQueryString( 'tab', 'emails' );
\IPS\Member::loggedIn()->language()->words['ads_ad_impressions'] = \IPS\Member::loggedIn()->language()->addToStack('ads_ad_sends');
Member::loggedIn()->language()->words['ads_ad_impressions'] = Member::loggedIn()->language()->addToStack('ads_ad_sends');
}
else
{
$where = array( array( 'ad_type!=?', \IPS\core\Advertisement::AD_EMAIL ) );
$where = array( array( 'ad_type!=?', Advertisement::AD_EMAIL ) );
$url = $url->setQueryString( 'tab', 'site' );
}
$table = new \IPS\Helpers\Table\Db( 'core_advertisements', $url, $where );
$table = new TableDb( 'core_advertisements', $url, $where );
$table->langPrefix = 'ads_';
$table->rowClasses = array( 'ad_html' => array( 'ipsTable_wrap' ) );
@@ -130,11 +174,12 @@ class _advertisements extends \IPS\Dispatcher\Controller
{
$table->include[] = 'ad_clicks';
$table->include[] = 'ad_active';
$table->include[] = 'ad_ctr';
}
$table->mainColumn = 'word_custom';
$table->noSort = array( 'ad_images', 'ad_html' );
$table->joins = array(
array( 'select' => 'w.word_custom', 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_advert_', core_advertisements.ad_id ) AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'select' => 'w.word_custom', 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_advert_', core_advertisements.ad_id ) AND w.lang_id=" . Member::loggedIn()->language()->id )
);
/* Default sort options */
@@ -143,11 +188,11 @@ class _advertisements extends \IPS\Dispatcher\Controller
$table->quickSearch = 'word_custom';
$table->advancedSearch = array(
'ad_html' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'ad_start' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'ad_end' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'ad_impressions' => \IPS\Helpers\Table\SEARCH_NUMERIC,
'ad_clicks' => \IPS\Helpers\Table\SEARCH_NUMERIC,
'ad_html' => SEARCH_CONTAINS_TEXT,
'ad_start' => SEARCH_DATE_RANGE,
'ad_end' => SEARCH_DATE_RANGE,
'ad_impressions' => SEARCH_NUMERIC,
'ad_clicks' => SEARCH_NUMERIC,
);
/* Filters */
@@ -157,7 +202,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
);
/* If Nexus is installed, we get the pending filter too */
if( \IPS\Application::appIsEnabled( 'nexus' ) AND $email === FALSE )
if( Application::appIsEnabled( 'nexus' ) AND $email === FALSE )
{
$table->filters['ad_filters_pending'] = 'ad_active=-1';
}
@@ -166,54 +211,58 @@ class _advertisements extends \IPS\Dispatcher\Controller
$table->parsers = array(
'word_custom' => function( $val, $row )
{
return \IPS\Member::loggedIn()->language()->checkKeyExists( "core_advert_{$row['ad_id']}" ) ? \IPS\Member::loggedIn()->language()->addToStack( "core_advert_{$row['ad_id']}" ) : \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( 'ad_title_none', array( 'ipsType_light' ) );
return Member::loggedIn()->language()->checkKeyExists( "core_advert_{$row['ad_id']}" ) ? Member::loggedIn()->language()->addToStack( "core_advert_{$row['ad_id']}" ) : Theme::i()->getTemplate( 'global' )->shortMessage( 'ad_title_none', array( 'i-color_soft' ) );
},
'ad_html' => function( $val, $row )
{
if( $row['ad_type'] == \IPS\core\Advertisement::AD_HTML )
if( $row['ad_type'] == Advertisement::AD_HTML )
{
$preview = \IPS\Theme::i()->getTemplate( 'promotion' )->advertisementIframePreview( $row['ad_id'] );
$preview = Theme::i()->getTemplate( 'promotion' )->advertisementIframePreview( $row['ad_id'] );
}
else
{
$advert = \IPS\core\Advertisement::constructFromData( $row );
$advert = Advertisement::constructFromData( $row );
if( !\count( $advert->_images ) )
if( !count( $advert->_images ) )
{
return '';
}
$preview = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->advertisementImage( $advert, \IPS\Http\Url::external( $advert->link ) );
$preview = Theme::i()->getTemplate( 'global', 'core', 'global' )->advertisementImage( $advert, Url::external( $advert->link ) );
}
return $preview;
},
'ad_active' => function( $val, $row )
{
return \IPS\Theme::i()->getTemplate( 'promotion' )->activeBadge( $row['ad_id'], ( $val == -1 ) ? 'ad_filters_pending' : ( ( $val == 0 ) ? 'ad_filters_inactive' : 'ad_filters_active' ), $val, $row );
return Theme::i()->getTemplate( 'promotion' )->activeBadge( $row['ad_id'], ( $val == -1 ) ? 'ad_filters_pending' : ( ( $val == 0 ) ? 'ad_filters_inactive' : 'ad_filters_active' ), $val, $row );
},
'ad_clicks' => function( $val, $row )
{
return $row['ad_html'] ? \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( 'unavailable', array( 'ipsType_light' ) ) : $val;
return $row['ad_html'] ? Theme::i()->getTemplate( 'global' )->shortMessage( 'unavailable', array( 'i-color_soft' ) ) : $val;
},
'ad_impressions' => function( $val, $row )
'ad_impressions' => function( $val )
{
return $val;
},
'ad_email_views' => function( $val, $row )
'ad_ctr' => function( $val, $row )
{
return \intval( $val );
return ( $row['ad_impressions'] ) ? round( ( $row['ad_clicks'] / $row['ad_impressions'] ) * 100, 2 ) . "%" : Theme::i()->getTemplate( 'global' )->shortMessage( 'unavailable', array( 'i-color_soft' ) );
},
'ad_email_views' => function( $val )
{
return intval( $val );
},
);
/* Specify the buttons */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_add' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_add' ) )
{
$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' ) )
'link' => Url::internal( 'app=core&module=promotion&controller=advertisements&do=form&type=' . ( ( $email === TRUE ) ? 'emails' : 'site' ) )
)
);
}
@@ -222,14 +271,14 @@ class _advertisements extends \IPS\Dispatcher\Controller
{
$return = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_edit' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_edit' ) )
{
if ( $row['ad_active'] == -1 )
{
$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'] )->csrf(),
'link' => Url::internal( 'app=core&module=promotion&controller=advertisements&do=toggle&status=1&id=' . $row['ad_id'] )->csrf(),
'hotkey' => 'a',
);
}
@@ -237,17 +286,17 @@ class _advertisements extends \IPS\Dispatcher\Controller
$return['edit'] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=form&id=' . $row['ad_id'] ),
'link' => Url::internal( 'app=core&module=promotion&controller=advertisements&do=form&id=' . $row['ad_id'] ),
'hotkey' => 'e',
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_delete' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_delete' ) )
{
$return['delete'] = array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=delete&id=' . $row['ad_id'] ),
'link' => Url::internal( 'app=core&module=promotion&controller=advertisements&do=delete&id=' . $row['ad_id'] ),
'data' => array( 'delete' => '' ),
);
}
@@ -264,25 +313,25 @@ class _advertisements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function settings()
protected function settings() : void
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Select( 'ads_circulation', \IPS\Settings::i()->ads_circulation, TRUE, array( 'options' => array( 'random' => 'ad_circ_random', 'newest' => 'ad_circ_newest', 'oldest' => 'ad_circ_oldest', 'least' => 'ad_circ_leasti' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'ads_force_sidebar', \IPS\Settings::i()->ads_force_sidebar, TRUE ) );
$form = new Form;
$form->add( new Select( 'ads_circulation', Settings::i()->ads_circulation, TRUE, array( 'options' => array( 'random' => 'ad_circ_random', 'newest' => 'ad_circ_newest', 'oldest' => 'ad_circ_oldest', 'least' => 'ad_circ_leasti' ) ) ) );
$form->add( new YesNo( 'ads_force_sidebar', Settings::i()->ads_force_sidebar, TRUE ) );
$form->add( new YesNo( 'ads_txt_enabled', Settings::i()->ads_txt_enabled, FALSE, array( 'togglesOn' => array( 'ads_txt' ) ) ) );
$form->add( new TextArea( 'ads_txt', Settings::i()->ads_txt, FALSE, array( 'rows' => 8 ), NULL, NULL, NULL, 'ads_txt' ) );
$form->add( new YesNo( 'ajax_pagination', Settings::i()->ajax_pagination, FALSE ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplog_ad_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' ), 'saved' );
Session::i()->log( 'acplog_ad_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=promotion&controller=advertisements' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('ad_settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'ad_settings', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('ad_settings');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'ad_settings', $form, FALSE );
}
/**
@@ -290,35 +339,32 @@ class _advertisements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function delete()
protected function delete() : void
{
/* Permission check */
\IPS\Dispatcher::i()->checkAcpPermission( 'advertisements_delete' );
Dispatcher::i()->checkAcpPermission( 'advertisements_delete' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
/* Get our record */
try
{
$record = \IPS\core\Advertisement::load( \IPS\Request::i()->id );
$record = Advertisement::load( Request::i()->id );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C157/2', 404, '' );
Output::i()->error( 'node_error', '2C157/2', 404, '' );
}
/* Delete the record */
$record->delete();
\IPS\Lang::deleteCustom( 'core', 'advert_' . $record->id );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
Lang::deleteCustom( 'core', 'advert_' . $record->id );
/* Log and redirect */
\IPS\Session::i()->log( 'acplog_ad_deleted', array() );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' ), 'deleted' );
Session::i()->log( 'acplog_ad_deleted' );
Output::i()->redirect( Url::internal( 'app=core&module=promotion&controller=advertisements' ), 'deleted' );
}
/**
@@ -327,55 +373,52 @@ class _advertisements extends \IPS\Dispatcher\Controller
* @note This also takes care of approving a pending advertisement
* @return void
*/
protected function toggle()
protected function toggle() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
/* Get our record */
try
{
$record = \IPS\core\Advertisement::load( \IPS\Request::i()->id );
$record = Advertisement::load( Request::i()->id );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C157/5', 404, '' );
Output::i()->error( 'node_error', '2C157/5', 404, '' );
}
/* Toggle the record */
$record->active = (int) \IPS\Request::i()->status;
$record->active = (int) Request::i()->status;
$record->save();
/* Reset ads_exist setting */
$adsExist = (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_advertisements', 'ad_active=1' )->first();
if ( $adsExist != \IPS\Settings::i()->ads_exist )
$adsExist = (bool) Db::i()->select( 'COUNT(*)', 'core_advertisements', 'ad_active=1' )->first();
if ( $adsExist != Settings::i()->ads_exist )
{
\IPS\Settings::i()->changeValues( array( 'ads_exist' => $adsExist ) );
Settings::i()->changeValues( array( 'ads_exist' => $adsExist ) );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* Log and redirect */
if( $record->active == -1 )
{
\IPS\Session::i()->log( 'acplog_ad_approved', array() );
Session::i()->log( 'acplog_ad_approved' );
}
else if( $record->active == 1 )
{
\IPS\Session::i()->log( 'acplog_ad_enabled', array() );
Session::i()->log( 'acplog_ad_enabled' );
}
else
{
\IPS\Session::i()->log( 'acplog_ad_disabled', array() );
Session::i()->log( 'acplog_ad_disabled' );
}
if( \IPS\Request::i()->isAjax() )
if( Request::i()->isAjax() )
{
\IPS\Output::i()->json( 'OK' );
Output::i()->json( 'OK' );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements' )->setQueryString( 'filter', \IPS\Request::i()->filter ), \IPS\Request::i()->status ? 'ad_toggled_visible' : 'ad_toggled_notvisible' );
Output::i()->redirect( Url::internal( 'app=core&module=promotion&controller=advertisements' )->setQueryString( 'filter', Request::i()->filter ), Request::i()->status ? 'ad_toggled_visible' : 'ad_toggled_notvisible' );
}
}
@@ -384,140 +427,159 @@ class _advertisements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function form()
protected function form() : void
{
/* Are we editing? */
if( isset( \IPS\Request::i()->id ) )
if( isset( Request::i()->id ) )
{
/* Permission check */
\IPS\Dispatcher::i()->checkAcpPermission( 'advertisements_edit' );
Dispatcher::i()->checkAcpPermission( 'advertisements_edit' );
try
{
$record = \IPS\core\Advertisement::load( \IPS\Request::i()->id );
$record = Advertisement::load( Request::i()->id );
if( $record->type == \IPS\core\Advertisement::AD_EMAIL )
if( $record->type == Advertisement::AD_EMAIL )
{
\IPS\Request::i()->type = 'emails';
\IPS\Member::loggedIn()->language()->words['ad_impressions'] = \IPS\Member::loggedIn()->language()->addToStack('ad_sends_so_far');
Request::i()->type = 'emails';
Member::loggedIn()->language()->words['ad_impressions'] = Member::loggedIn()->language()->addToStack('ad_sends_so_far');
}
else
{
\IPS\Request::i()->type = 'site';
Request::i()->type = 'site';
}
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C157/1', 404, '' );
Output::i()->error( 'node_error', '2C157/1', 404, '' );
}
}
else
{
/* Permission check */
\IPS\Dispatcher::i()->checkAcpPermission( 'advertisements_add' );
Dispatcher::i()->checkAcpPermission( 'advertisements_add' );
$record = new \IPS\core\Advertisement;
$record = new Advertisement;
}
/* 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 = new Form;
$form->add( new Translatable( 'ad_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( !$record->id ) ? NULL : "core_advert_{$record->id}" ) ) );
if( \IPS\Request::i()->type != 'emails' )
if( 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' ) );
$form->add( new Radio( 'ad_type', ( $record->id ) ? $record->type : Advertisement::AD_HTML, TRUE, array( 'options' => array( 1 => 'ad_type_html', 2 => 'ad_type_image' ), 'toggles' => array( Advertisement::AD_HTML => array( 'ad_html', 'ad_html_specify_https', 'ad_maximums_html', 'ad_location', 'ad_exempt' ), 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 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');
$form->add( new Codemirror( 'ad_html', ( $record->id ) ? $record->html : NULL, NULL, array(), function( $val ) {
if( 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' ) );
$form->add( new 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 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 FormUrl( 'ad_url', ( $record->id ) ? $record->link : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_url' ) );
if( \IPS\Request::i()->type != 'emails' )
if( Request::i()->type != 'emails' )
{
$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 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 Upload( 'ad_image', ( $record->id ) ? ( ( isset( $record->_images['large'] ) and $record->_images['large'] ) ? File::get( 'core_Advertisements', $record->_images['large'] ) : NULL ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Advertisements' ), NULL, NULL, NULL, 'ad_image' ) );
if( \IPS\Request::i()->type != 'emails' )
if( 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 YesNo( 'ad_image_more', $record->id && ( ( isset( $record->_images['medium'] ) and $record->_images['medium'] ) or ( ( isset( $record->_images['small'] ) and $record->_images['small'] ) ) ), FALSE, array( 'togglesOn' => array( 'ad_image_small', 'ad_image_medium' ) ), NULL, NULL, NULL, 'ad_image_more' ) );
$form->add( new Upload( 'ad_image_small', ( $record->id ) ? ( ( isset( $record->_images['small'] ) and $record->_images['small'] ) ? 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 Upload( 'ad_image_medium', ( $record->id ) ? ( ( isset( $record->_images['medium'] ) and $record->_images['medium'] ) ? 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' ) );
$form->add( new Text( 'ad_image_alt', ( $record->id ) ? $record->image_alt : NULL, FALSE, array(), NULL, NULL, NULL, 'ad_image_alt' ) );
if( \IPS\Request::i()->type != 'emails' )
if( Request::i()->type != 'emails' )
{
$currentValues = ( $record->id ) ? json_decode( $record->additional_settings, TRUE ) : array();
/* 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(),
'ad_global_header' => array( 'ad_apps' ),
'ad_global_footer' => array( 'ad_apps' ),
'ad_sidebar' => array( 'ad_apps' ),
);
$currentValues = ( $record->id ) ? json_decode( $record->additional_settings, TRUE ) : array();
$settingFields = [];
/* Add a field to restrict by app */
$settingFields[] = new Node( 'ad_apps', $currentValues['ad_apps'] ?? 0, false, array(
'class' => Application::class,
'multiple' => true,
'zeroVal' => 'all',
'subnodes' => false
), null, null, null, 'ad_apps' );
/* Now grab ad location extensions */
foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
{
/* @var AdvertisementLocationsAbstract $extension */
$result = $extension->getSettings( $currentValues );
$defaultLocations = array_merge( $defaultLocations, $result['locations'] );
/* If this is a list view, add setting fields for interaval and repeat */
if( $extension::$listView )
{
$settingFields[] = new Number( 'ad_view_number', ( isset( $currentValues['ad_view_number'] ) AND $currentValues['ad_view_number'] ) ? $currentValues['ad_view_number'] : 1, FALSE, array( 'min' => 1 ), NULL, NULL, Member::loggedIn()->language()->addToStack('ad_view_number_suffix'), 'ad_view_number' );
$settingFields[] = new Number( 'ad_view_repeat', $currentValues['ad_view_repeat'] ?? 1, FALSE, array( 'unlimited' => -1 ), NULL, NULL, Member::loggedIn()->language()->addToStack('ad_view_repeat_suffix'), 'ad_view_repeat' );
foreach( $result['locations'] as $location => $toggles )
{
$defaultLocations[$location][] = 'ad_view_number';
$defaultLocations[$location][] = 'ad_view_repeat';
}
}
if( isset( $result['settings'] ) )
{
foreach( $result['settings'] as $setting )
{
$form->add( $setting );
}
$settingFields = $settingFields + $result['settings'];
}
}
$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',
/* Make location optional so that you can have an active ad for widgets only */
$form->add( new CheckboxSet( 'ad_location',
$locations,
TRUE,
false,
array(
'options' => array_combine( array_keys( $defaultLocations ), array_keys( $defaultLocations ) ),
'toggles' => $defaultLocations,
'noDefault' => true
),
NULL,
NULL,
NULL,
'ad_location'
) );
$form->add( new \IPS\Helpers\Form\Stack( 'ad_location_custom', $customLocations, FALSE, array(), NULL, NULL, NULL, 'ad_location_custom' ) );
foreach( $settingFields as $settingField )
{
$form->add( $settingField );
}
/* Generic fields available for both html and image ads */
$form->add( new \IPS\Helpers\Form\CheckboxSet( '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', 'impliedUnlimited' => TRUE ), NULL, NULL, NULL, 'ad_exempt' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_nocontent_page_output', ( $record->id ) ? $record->nocontent_page_output : FALSE ) );
$form->add( new CheckboxSet( 'ad_exempt', ( $record->id ) ? ( ( $record->exempt == '*' ) ? '*' : json_decode( $record->exempt, TRUE ) ) : '*', FALSE, array( 'options' => Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ), NULL, NULL, NULL, 'ad_exempt' ) );
$form->add( new YesNo( 'ad_nocontent_page_output', ( $record->id ) ? $record->nocontent_page_output : FALSE ) );
}
else
{
@@ -525,7 +587,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
$containerClasses = array();
$containerToggles = array();
foreach( \IPS\Content::routedClasses( FALSE, FALSE, TRUE ) as $contentItemClass )
foreach( Content::routedClasses( FALSE, FALSE, TRUE ) as $contentItemClass )
{
if( isset( $contentItemClass::$containerNodeClass ) AND $contentItemClass::$containerNodeClass AND !isset( $containerClasses[ $contentItemClass::$containerNodeClass ] ) )
{
@@ -536,49 +598,49 @@ class _advertisements extends \IPS\Dispatcher\Controller
}
}
if( \count( $containerClasses ) )
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' ) );
$form->add( new 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 ) ) );
$form->add( new 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 );
Member::loggedIn()->language()->words[ 'node_' . md5( $classname ) ] = Member::loggedIn()->language()->addToStack( $classname::$nodeTitle );
}
}
}
/* 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' ) ) );
$form->add( new Date( 'ad_start', ( $record->id ) ? DateTime::ts( $record->start ) : new DateTime, TRUE ) );
$form->add( new Date( 'ad_end', ( $record->id ) ? ( $record->end ? DateTime::ts( $record->end ) : 0 ) : 0, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'indefinitely' ) ) );
/* Number of clicks, number of impressions */
if( $record->id )
{
$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' ) );
$form->add( new Number( 'ad_impressions', ( $record->id ) ? $record->impressions : 0, FALSE, array(), NULL, NULL, NULL, 'ad_impressions' ) );
$form->add( new Number( 'ad_clicks', ( $record->id ) ? $record->clicks : 0, FALSE, array(), NULL, NULL, NULL, 'ad_clicks' ) );
if( \IPS\Request::i()->type == 'emails' )
if( 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' ) );
$form->add( new 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 */
if( \IPS\Request::i()->type != 'emails' )
if( 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 Number( 'ad_maximums_html', ( $record->id ) ? $record->maximum_value : -1, FALSE, array( 'unlimited' => -1 ), NULL, NULL, 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(
$form->add( new Custom( 'ad_maximums_image', array( 'value' => ( $record->id ) ? $record->maximum_value : -1, 'type' => ( $record->id ) ? $record->maximum_unit : 'i' ), FALSE, array(
'getHtml' => function( $element )
{
return \IPS\Theme::i()->getTemplate( 'promotion', 'core' )->imageMaximums( $element->name, $element->value['value'], $element->value['type'] );
return Theme::i()->getTemplate( 'promotion', 'core' )->imageMaximums( $element->name, $element->value['value'], $element->value['type'] );
},
'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' );
}
@@ -590,48 +652,42 @@ class _advertisements extends \IPS\Dispatcher\Controller
/* Handle submissions */
if ( $values = $form->values() )
{
if( \IPS\Request::i()->type != 'emails' )
if( Request::i()->type != 'emails' )
{
$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;
$values['ad_type'] = Advertisement::AD_EMAIL;
}
/* Let us start with the easy stuff... */
$record->type = $values['ad_type'];
$record->location = implode( ',', $locations );
$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->location = is_array( $locations ) ? implode( ',', $locations ) : '';
$record->html = ( $values['ad_type'] == Advertisement::AD_HTML ) ? $values['ad_html'] : NULL;
$record->link = ( $values['ad_type'] != Advertisement::AD_HTML ) ? $values['ad_url'] : NULL;
$record->image_alt = ( $values['ad_type'] != Advertisement::AD_HTML ) ? $values['ad_image_alt'] : NULL;
$record->new_window = ( $values['ad_type'] == Advertisement::AD_IMAGES ) ? $values['ad_new_window'] : 0;
$record->impressions = ( isset( $values['ad_impressions'] ) ) ? $values['ad_impressions'] : 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->clicks = ( $values['ad_type'] != Advertisement::AD_HTML AND isset( $values['ad_clicks'] ) ) ? $values['ad_clicks'] : 0;
$record->email_views = ( $values['ad_type'] == 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'] == \IPS\core\Advertisement::AD_HTML ) ? $values['ad_html_https'] : NULL;
$record->html_https = ( $values['ad_type'] == 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_type'] != \IPS\core\Advertisement::AD_EMAIL ) ? ( $values['ad_exempt'] == '*' ) ? '*' : json_encode( $values['ad_exempt'] ) : NULL;
$record->exempt = ( $values['ad_type'] != Advertisement::AD_EMAIL ) ? ( $values['ad_exempt'] == '*' ) ? '*' : json_encode( $values['ad_exempt'] ) : NULL;
$record->images = NULL;
$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->maximum_value = ( $values['ad_type'] == Advertisement::AD_HTML ) ? $values['ad_maximums_html'] : $values['ad_maximums_image']['value'];
$record->maximum_unit = ( $values['ad_type'] == Advertisement::AD_HTML ) ? 'i' : $values['ad_maximums_image']['type'];
$record->additional_settings = NULL;
$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;
$record->html_https_set = ( $values['ad_type'] == Advertisement::AD_HTML ) ? $values['ad_html_specify_https'] : 0;
$record->nocontent_page_output = $values['ad_nocontent_page_output'] ?? FALSE;
/* Figure out the ad_images */
$images = array();
if( $values['ad_type'] == \IPS\core\Advertisement::AD_IMAGES )
if( $values['ad_type'] == Advertisement::AD_IMAGES )
{
$images = array( 'large' => (string) $values['ad_image'] );
@@ -656,7 +712,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
$values['ad_image_medium']->delete();
}
}
elseif( $values['ad_type'] == \IPS\core\Advertisement::AD_EMAIL )
elseif( $values['ad_type'] == Advertisement::AD_EMAIL )
{
$images = array( 'large' => (string) $values['ad_image'] );
@@ -671,7 +727,7 @@ class _advertisements extends \IPS\Dispatcher\Controller
$values['ad_image_medium']->delete();
}
}
elseif( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML )
elseif( $values['ad_type'] == 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'] )
@@ -691,38 +747,46 @@ class _advertisements extends \IPS\Dispatcher\Controller
}
/* 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 ) )
if( $record->id AND count( $record->_images ) AND ( $values['ad_type'] == Advertisement::AD_HTML OR $values['ad_type'] == Advertisement::AD_EMAIL ) )
{
if( $values['ad_type'] == \IPS\core\Advertisement::AD_HTML )
if( $values['ad_type'] == Advertisement::AD_HTML )
{
\IPS\File::get( 'core_Advertisements', $record->_images['large'] )->delete();
File::get( 'core_Advertisements', $record->_images['large'] )->delete();
}
if( isset( $record->_images['small'] ) )
{
\IPS\File::get( 'core_Advertisements', $record->_images['small'] )->delete();
File::get( 'core_Advertisements', $record->_images['small'] )->delete();
}
if( isset( $record->_images['medium'] ) )
{
\IPS\File::get( 'core_Advertisements', $record->_images['medium'] )->delete();
File::get( 'core_Advertisements', $record->_images['medium'] )->delete();
}
}
$record->images = json_encode( $images );
/* Any additional settings to save? */
$additionalSettings = array();
$additionalSettings = array(
'ad_apps' => ( isset( $values['ad_apps'] ) AND $values['ad_apps'] != 0 ) ? array_keys( $values['ad_apps'] ) : 0
);
if( $values['ad_type'] == \IPS\core\Advertisement::AD_EMAIL )
if( $values['ad_type'] == Advertisement::AD_EMAIL )
{
$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 )
foreach ( Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
{
if( $extension::$listView )
{
$additionalSettings['ad_view_number'] = $values['ad_view_number'] ?? 1;
$additionalSettings['ad_view_repeat'] = $values['ad_view_repeat'] ?? 0;
}
$settings = $extension->parseSettings( $values );
$additionalSettings = array_merge( $additionalSettings, $settings );
@@ -734,34 +798,31 @@ class _advertisements extends \IPS\Dispatcher\Controller
/* Insert or update */
if( $record->id )
{
\IPS\Session::i()->log( 'acplog_ad_edited', array() );
Session::i()->log( 'acplog_ad_edited' );
}
else
{
\IPS\Session::i()->log( 'acplog_ad_added', array() );
Session::i()->log( 'acplog_ad_added' );
}
$record->save();
/* Save if any exist */
$adsExist = $record->active ? TRUE : (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_advertisements', 'ad_active=1' )->first();
$adsExist = $record->active ? TRUE : (bool) Db::i()->select( 'COUNT(*)', 'core_advertisements', 'ad_active=1' )->first();
if ( $adsExist != \IPS\Settings::i()->ads_exist )
if ( $adsExist != Settings::i()->ads_exist )
{
\IPS\Settings::i()->changeValues( array( 'ads_exist' => $adsExist ) );
Settings::i()->changeValues( array( 'ads_exist' => $adsExist ) );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* Set the title */
\IPS\Lang::saveCustom( 'core', 'core_advert_' . $record->id, $values[ 'ad_title' ] );
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&tab=' . \IPS\Request::i()->type ), 'saved' );
Output::i()->redirect( Url::internal( 'app=core&module=promotion&controller=advertisements&tab=' . Request::i()->type ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( ( !isset( \IPS\Request::i()->id ) ) ? 'add_advertisement' : 'edit_advertisement' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( ( !isset( \IPS\Request::i()->id ) ) ? 'add_advertisement' : 'edit_advertisement', $form );
Output::i()->title = Member::loggedIn()->language()->addToStack( ( !isset( Request::i()->id ) ) ? 'add_advertisement' : 'edit_advertisement' );
Output::i()->output = Theme::i()->getTemplate('global')->block( ( !isset( Request::i()->id ) ) ? 'add_advertisement' : 'edit_advertisement', $form );
}
/**
@@ -769,30 +830,30 @@ class _advertisements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function getHtml()
protected function getHtml() : void
{
/* Are we editing? */
if( \IPS\Request::i()->id )
if( Request::i()->id )
{
try
{
$record = \IPS\core\Advertisement::load( \IPS\Request::i()->id );
$record = Advertisement::load( Request::i()->id );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C157/6', 404, '' );
Output::i()->error( 'node_error', '2C157/6', 404, '' );
}
}
else
{
\IPS\Output::i()->error( 'node_error', '2C157/7', 404, '' );
Output::i()->error( 'node_error', '2C157/7', 404, '' );
}
$preview = '';
if( $record->html )
{
if( \IPS\Request::i()->isSecure() AND $record->html_https_set )
if( Request::i()->isSecure() AND $record->html_https_set )
{
$preview = $record->html_https;
}
@@ -802,9 +863,9 @@ class _advertisements extends \IPS\Dispatcher\Controller
}
}
$preview = preg_replace( "/<script(?:[^>]*?)?>.*<\/script>/ims", \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( 'ad_script_disabled', array( 'ipsType_light' ) ), $preview );
$preview = preg_replace( "/<script(?:[^>]*?)?>.*<\/script>/ims", Theme::i()->getTemplate( 'global' )->shortMessage( 'ad_script_disabled', array( 'i-color_soft' ) ), $preview );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->blankTemplate( $preview ) );
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core', 'admin' )->blankTemplate( $preview ) );
}
/**
@@ -812,9 +873,9 @@ class _advertisements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function adsense()
protected function adsense() : void
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('google_adsense_header');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('promotion')->adsenseHelp();
Output::i()->title = Member::loggedIn()->language()->addToStack('google_adsense_header');
Output::i()->output = Theme::i()->getTemplate('promotion')->adsenseHelp();
}
}
@@ -1,434 +0,0 @@
<?php
/**
* @brief promote
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 14 Feb 2017
*/
namespace IPS\core\modules\admin\promotion;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* promote
*/
class _promote extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* @brief Active tab
*/
protected $activeTab = '';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'promote_manage' );
/* Get tab content */
$this->activeTab = \IPS\Request::i()->tab ?: 'internal';
parent::execute();
}
/**
* Promote Settings
*
* @return void
*/
protected function manage()
{
/* Work out output */
$methodFunction = '_manage' . mb_ucfirst( $this->activeTab );
$activeTabContents = $this->$methodFunction();
/* If this is an AJAX request, just return it */
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $activeTabContents;
return;
}
/* Build tab list */
$tabs = array();
$tabs['internal'] = 'promote_tab_internal';
$tabs['permissions'] = 'promote_tab_permissions';
$tabs['twitter'] = 'promote_tab_twitter';
$tabs['links'] = 'promote_tab_links';
$tabs['schedule'] = 'promote_tab_schedule';
/* Buttons for logs */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'promote_logs' ) )
{
\IPS\Output::i()->sidebar['actions']['actionLogs'] = array(
'title' => 'promote_logs',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=promote&do=logs' ),
);
}
/* Display */
if ( $activeTabContents )
{
$output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( \IPS\Member::loggedIn()->language()->addToStack( 'promote_acp_blurb' ) );
/* Put up a little warning about permissions */
$enabledServices = \IPS\Db::i()->select( 'count(*)', 'core_social_promote_sharers', array( 'sharer_enabled=1' ) )->first();
if ( $enabledServices and ! \IPS\core\Promote::canPromote() )
{
/* We do not have permission to promote, so lets show a notice about that */
$output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'promote_no_permission_acp', 'info' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_promotion_promote');
\IPS\Output::i()->output = $output . \IPS\Theme::i()->getTemplate( 'global' )->tabs( $tabs, $this->activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote" ) );
}
}
/**
* Manage Links
*
* @return string
*/
protected function _manageLinks()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\YesNo( 'bitly_enabled', \IPS\Settings::i()->bitly_enabled, FALSE, array( 'togglesOn' => array( 'bitly_token' ) ), NULL, NULL, NULL, 'bitly_enabled' ) );
$form->add( new \IPS\Helpers\Form\Text( 'bitly_token', \IPS\Settings::i()->bitly_token, FALSE, array(), function( $val )
{
try
{
$request = \IPS\Http\Url::external( "https://api-ssl.bitly.com/v4/shorten" )->request()
->setHeaders([
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $val
])
->post( json_encode( [
'long_url' => 'https://www.invisioncommunity.com',
] ) );
if ( (int) $request->httpResponseCode !== 201 )
{
throw new \DomainException("bitly_auth_failed");
}
}
catch ( \IPS\Http\Request\Exception $e )
{
throw new \DomainException("bitly_auth_failed");
}
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('bitly_generate_token'), 'bitly_token' ) );
/* Are we saving? */
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__promote_save', array( "acplogs__promote_changed_links" => true ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=" . \IPS\Request::i()->tab ), 'saved' );
}
return $form;
}
/**
* Manage Links
*
* @return string
*/
protected function _manageSchedule()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Stack( 'promote_scheduled', explode( ',', \IPS\Settings::i()->promote_scheduled ), FALSE, array( 'stackFieldType' => 'Text', 'placeholder' => 'HH:MM' ), NULL, NULL, NULL, 'promote_scheduled' ) );
$form->add( new \IPS\Helpers\Form\Timezone( 'promote_tz', \IPS\Settings::i()->promote_tz, FALSE, array(), NULL, NULL, NULL, 'promote_tz' ) );
/* Are we saving? */
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__promote_save', array( "acplogs__promote_changed_schedule" => true ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=" . \IPS\Request::i()->tab ), 'saved' );
}
return $form;
}
/**
* Manage Permissions
*
* @return string
*/
protected function _managePermissions()
{
$form = new \IPS\Helpers\Form;
$groups = array();
foreach( \IPS\Member\Group::groups() as $group )
{
if ( $group->g_bitoptions['gbw_promote'] )
{
$groups[] = \IPS\Theme::i()->getTemplate( 'promote' )->groupLink( $group->g_id, $group->name );
}
}
$output = \IPS\Theme::i()->getTemplate( 'promote' )->permissionBlurb( $groups );
$form->add( new \IPS\Helpers\Form\Member( 'promote_members', \IPS\Settings::i()->promote_members ? array_map( array( 'IPS\Member', 'load' ), explode( "\n", \IPS\Settings::i()->promote_members ) ) : NULL, FALSE, array( 'multiple' => NULL ), NULL, NULL, NULL, 'promote_twitter_members' ) );
/* Are we saving? */
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__promote_save', array( "acplogs__promote_changed_permissions" => true ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=" . \IPS\Request::i()->tab ), 'saved' );
}
return $output . $form;
}
/**
* Manage Internal
*
* @return string
*/
protected function _manageInternal()
{
$account = \IPS\core\Promote::getPromoter('Internal')->setMember( \IPS\Member::loggedIn() );
$output = \IPS\Theme::i()->getTemplate( 'promote' )->internalBlurb();
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\YesNo( 'promote_internal_enabled', $account->enabled, FALSE, array(), NULL, NULL, NULL, 'promote_internal_enabled' ) );
/* Are we saving? */
if ( $values = $form->values() )
{
$account->enabled = $values['promote_internal_enabled'];
$account->save();
$form->saveAsSettings( array( 'promote_community_enabled' => $account->enabled ) );
\IPS\Session::i()->log( 'acplogs__promote_save', array( "acplogs__promote_changed_community" => true ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=" . \IPS\Request::i()->tab ), 'saved' );
}
return $output . $form;
}
/**
* Manage Twitter
*
* @return string
*/
protected function _manageTwitter()
{
$twitter = \IPS\Login\Handler::findMethod('IPS\Login\Handler\Oauth1\Twitter');
$account = \IPS\core\Promote::getPromoter('Twitter')->setMember( \IPS\Member::loggedIn() );
/* Have we set up Twitter yet? */
if ( !$twitter OR !$twitter->settings['consumer_key'] )
{
/* Nope, so lets do that first... */
return \IPS\Theme::i()->getTemplate( 'promote' )->warningNoTwitterApp();
}
/* Have we linked to a Twitter account? */
if ( ! $account->settings['token'] )
{
/* Nope, so lets do that now... */
return \IPS\Theme::i()->getTemplate( 'promote' )->warningNoTwitterUser();
}
/* Do we have post to page permissions? */
$response = $account->canPostToPage();
if ( $response !== TRUE )
{
/* Token stores permissions, so wipe it */
$account->enabled = FALSE;
$account->saveSettings( array(
'token' => NULL,
'secret' => NULL,
'owner' => NULL,
'name' => NULL
) );
return \IPS\Theme::i()->getTemplate( 'promote' )->warningNoTwitterPostToPagePermission( $response );
}
$form = new \IPS\Helpers\Form;
if ( isset( \IPS\Request::i()->clear ) and \IPS\Request::i()->clear === 'true' )
{
\IPS\Session::i()->csrfCheck();
/* We want to clear settings */
$account->enabled = FALSE;
$account->saveSettings( array(
'token' => NULL,
'secret' => NULL,
'owner' => NULL,
'name' => NULL
) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=twitter" ) );
}
$owner = \IPS\Member::load( $account->settings['owner'] );
$output = '';
if ( $account->settings['owner'] and $account->settings['name'] )
{
try
{
$output = \IPS\Theme::i()->getTemplate( 'promote' )->twitterOwnedBy( $owner, $account->settings['name'] );
}
catch( \OutOfRangeException $e )
{
/* Member no longer exists, so clear settings */
$account->enabled = FALSE;
$account->saveSettings( array(
'token' => NULL,
'secret' => NULL,
'owner' => NULL,
'name' => NULL
) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=twitter" ) );
}
}
$form->add( new \IPS\Helpers\Form\YesNo( 'promote_twitter_enabled', $account->enabled, FALSE, array( 'togglesOn' => array() ), NULL, NULL, NULL, 'promote_twitter_enabled' ) );
$form->add( new \IPS\Helpers\Form\Stack( 'promote_twitter_tags', $account->settings['tags'], FALSE, array( 'stackFieldType' => 'Text' ), NULL, NULL, NULL, 'promote_twitter_tags' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'promote_twitter_tags_method', $account->settings['tags_method'], FALSE, array( 'options' => array(
'fill' => 'promote_twitter_tags_method_fill',
'trim' => 'promote_twitter_tags_method_trim'
) ), NULL, NULL, NULL, 'promote_twitter_tags_method' ) );
/* Are we saving? */
if ( $values = $form->values() )
{
if ( \is_array( $values['promote_twitter_tags'] ) )
{
array_walk( $values['promote_twitter_tags'], function( &$value )
{
$value = str_replace( '#', '', $value );
} );
}
$account->enabled = $values['promote_twitter_enabled'];
$save = array(
'tags' => $values['promote_twitter_tags'],
'tags_method' => $values['promote_twitter_tags_method']
);
$account->saveSettings( $save );
\IPS\Session::i()->log( 'acplogs__promote_save', array( "acplogs__promote_changed_twitter" => true ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=" . \IPS\Request::i()->tab ), 'saved' );
}
return $output . $form;
}
/**
* Response Logs
*
* @return void
*/
protected function logs()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_social_promote_content', \IPS\Http\Url::internal( 'app=core&module=promotion&controller=promote&do=logs' ), array( array( "response_promote_key != 'internal'" ) ) );
$table->langPrefix = 'promote_logs_';
$table->sortBy = $table->sortBy ?: 'response_date';
$table->sortDirection = $table->sortDirection ?: 'DESC';
$table->include = array( 'response_promote_id', 'response_promote_key', 'response_json', 'response_failed', 'response_date' );
$table->widths['response_json'] = '40';
/* Search */
$table->quickSearch = 'response_json';
/* Filters */
$table->filters = array(
'promote_logs_success' => 'response_failed = 0',
'promote_logs_unsuccessful' => 'response_failed = 1',
);
/* Custom parsers */
$table->parsers = array(
'response_date' => function( $val, $row )
{
return \IPS\DateTime::ts( $val );
},
'response_failed' => function( $val, $row )
{
return ( ! $val ) ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
},
'response_promote_id' => function( $val, $row )
{
try
{
$promote = \IPS\core\Promote::load( $val );
return htmlspecialchars( $promote->objectTitle, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', FALSE ) . ' (' . $val . ')';
}
catch ( \Exception $e ) { }
},
'response_promote_key' => function( $val, $row )
{
return \ucfirst( $val );
},
'response_json' => function( $val, $row )
{
$val = json_decode( $val, true );
return '<div data-ipstruncate data-ipstruncate-type="hide" data-ipstruncate-size="3 lines" class="ipsType_break">' . var_export( $val, true ) . "</div>";
}
);
/* Display */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=promote' ), \IPS\Member::loggedIn()->language()->addToStack( 'menu__core_promotion_promote' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('promote_logs');
\IPS\Output::i()->output = (string) $table;
}
/**
* Reschedule things
*
* @return void
*/
protected function reschedule()
{
\IPS\Session::i()->csrfCheck();
\IPS\core\Promote::rescheduleQueue();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=promote&tab=schedule" ), 'promote_rescheduled_done' );
}
}
+193 -178
View File
@@ -11,41 +11,78 @@
namespace IPS\core\modules\admin\promotion;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Application;
use IPS\Data\Store;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Dispatcher\Front;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Codemirror;
use IPS\Helpers\Form\Matrix;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Form\Text;
use IPS\Helpers\Form\TextArea;
use IPS\Helpers\Form\Url as FormUrl;
use IPS\Helpers\Form\YesNo;
use IPS\Helpers\Tree\Tree;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Task;
use IPS\Theme;
use IPS\Widget;
use RuntimeException;
use function count;
use function defined;
use function in_array;
use function is_array;
use function strpos;
use const IPS\CIC;
use const IPS\CIC2;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* SEO
*/
class _seo extends \IPS\Dispatcher\Controller
class seo extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* @brief Active tab
*/
protected $activeTab = '';
protected string $activeTab = '';
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'seo_furls' );
Dispatcher::i()->checkAcpPermission( 'seo_furls' );
/* Get tab content */
$this->activeTab = \IPS\Request::i()->tab ?: 'urls';
$this->activeTab = Request::i()->tab ?: 'urls';
\IPS\Output::i()->sidebar['actions']['rebuildsitemap'] = array(
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=seo&do=rebuildSitemap' )->csrf(),
Output::i()->sidebar['actions']['rebuildsitemap'] = array(
'link' => Url::internal( 'app=core&module=promotion&controller=seo&do=rebuildSitemap' )->csrf(),
'title' => 'rebuild_sitemap',
'icon' => 'history'
);
@@ -58,34 +95,34 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* Work out output */
$methodFunction = '_manage' . mb_ucfirst( $this->activeTab );
$methodFunction = '_manage' . IPS::mb_ucfirst( $this->activeTab );
$activeTabContents = $this->$methodFunction();
/* If this is an AJAX request, just return it */
if( \IPS\Request::i()->isAjax() )
if( Request::i()->isAjax() )
{
\IPS\Output::i()->output = $activeTabContents;
Output::i()->output = $activeTabContents;
return;
}
/* Build tab list */
$tabs = array();
if ( !\IPS\CIC AND \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_furls' ) )
if ( !CIC AND Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_furls' ) )
{
$tabs['urls'] = 'seo_tab_furls';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_sitemap' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_sitemap' ) )
{
$tabs['sitemap'] = 'seo_tab_sitemap';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_meta' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_meta' ) )
{
$tabs['metatags'] = 'seo_tab_metatags';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_furls' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'seo_furls' ) )
{
$tabs['robotstxt'] = 'seo_tab_robotstxt';
}
@@ -93,39 +130,39 @@ class _seo extends \IPS\Dispatcher\Controller
/* Display */
if ( $activeTabContents )
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_promotion_seo');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->tabs( $tabs, $this->activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo" ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__core_promotion_seo');
Output::i()->output = Theme::i()->getTemplate( 'global' )->tabs( $tabs, $this->activeTab, $activeTabContents, Url::internal( "app=core&module=promotion&controller=seo" ) );
}
}
/**
* Get setting to enable htaccess friendly URLs
*
* @param \IPS\Form $form Form to add the setting to
* @param Form $form Form to add the setting to
* @return void
*/
public static function htaccessSetting( $form )
public static function htaccessSetting( Form $form ) : void
{
$isApache = mb_stripos( $_SERVER['SERVER_SOFTWARE'], 'apache' ) !== FALSE;
$form->add( new \IPS\Helpers\Form\YesNo( 'htaccess_mod_rewrite', \IPS\Settings::i()->htaccess_mod_rewrite, TRUE, array(), NULL, NULL, NULL, 'htaccess_mod_rewrite' ) );
$form->add( new YesNo( 'htaccess_mod_rewrite', Settings::i()->htaccess_mod_rewrite, TRUE, array(), NULL, NULL, NULL, 'htaccess_mod_rewrite' ) );
if ( !$isApache )
{
\IPS\Member::loggedIn()->language()->words['htaccess_mod_rewrite_desc'] = \IPS\Member::loggedIn()->language()->get('htaccess_mod_rewrite_desc_na');
Member::loggedIn()->language()->words['htaccess_mod_rewrite_desc'] = Member::loggedIn()->language()->get('htaccess_mod_rewrite_desc_na');
}
if ( ( !isset( \IPS\Request::i()->htaccess_mod_rewrite ) and \IPS\Settings::i()->htaccess_mod_rewrite ) or \IPS\Request::i()->htaccess_mod_rewrite or \IPS\Request::i()->htaccess_mod_rewrite_checkbox )
if ( ( !isset( Request::i()->htaccess_mod_rewrite ) and Settings::i()->htaccess_mod_rewrite ) or Request::i()->htaccess_mod_rewrite or Request::i()->htaccess_mod_rewrite_checkbox )
{
try
{
$furlDefinition = \IPS\Http\Url::furlDefinition();
$response = \IPS\Http\Url::external( \IPS\Settings::i()->base_url . $furlDefinition['login']['friendly'] )->request( NULL, NULL, FALSE )->get();
if ( !\in_array( mb_substr( $response->httpResponseCode, 0, 1 ), array( '2', '3' ) ) and ( \IPS\Settings::i()->site_online OR $response->httpResponseCode != 503 ) )
$furlDefinition = Url::furlDefinition();
$response = Url::external( Settings::i()->base_url . $furlDefinition['login']['friendly'] )->request( NULL, NULL, FALSE )->get();
if ( !in_array( mb_substr( $response->httpResponseCode, 0, 1 ), array( '2', '3' ) ) and ( Settings::i()->site_online OR $response->httpResponseCode != 503 ) )
{
\IPS\Member::loggedIn()->language()->words['htaccess_mod_rewrite_warning'] = \IPS\Member::loggedIn()->language()->get( $isApache ? 'htaccess_mod_rewrite_err' : 'htaccess_mod_rewrite_err_na' );
Member::loggedIn()->language()->words['htaccess_mod_rewrite_warning'] = Member::loggedIn()->language()->get( $isApache ? 'htaccess_mod_rewrite_err' : 'htaccess_mod_rewrite_err_na' );
}
}
catch( \IPS\Http\Request\Exception $e )
{
\IPS\Member::loggedIn()->language()->words['htaccess_mod_rewrite_warning'] = \IPS\Member::loggedIn()->language()->get( $isApache ? 'htaccess_mod_rewrite_err' : 'htaccess_mod_rewrite_err_na' );
Member::loggedIn()->language()->words['htaccess_mod_rewrite_warning'] = Member::loggedIn()->language()->get( $isApache ? 'htaccess_mod_rewrite_err' : 'htaccess_mod_rewrite_err_na' );
}
}
}
@@ -135,48 +172,48 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return string
*/
protected function _manageRobotstxt()
protected function _manageRobotstxt() : string
{
$value = \IPS\Settings::i()->robots_txt;
if ( ! \in_array( \IPS\Settings::i()->robots_txt, ['off', 'default'] ) )
$value = Settings::i()->robots_txt;
if ( ! in_array( Settings::i()->robots_txt, ['off', 'default'] ) )
{
$value = 'custom';
}
$form = new \IPS\Helpers\Form;
$form = new Form;
if ( isset( \IPS\Request::i()->_saved ) )
if ( isset( Request::i()->_saved ) )
{
/* Do we have an existing robots.txt file in the community directory? */
$dir = trim( str_replace( \IPS\CP_DIRECTORY . '/index.php', '', $_SERVER['PHP_SELF'] ), '/' );
$dir = trim( str_replace( 'admin/index.php', '', $_SERVER['PHP_SELF'] ), '/' );
/* Oh, the community is in a directory, so we need the user to download the file and manually upload it to root */
if ( $dir )
{
$rootUrl = trim( str_replace( $dir, '', (string) \IPS\Http\Url::baseUrl() ), '/' );
if ( \IPS\Settings::i()->robots_txt === 'off' )
$rootUrl = trim( str_replace( $dir, '', Url::baseUrl() ), '/' );
if ( Settings::i()->robots_txt === 'off' )
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_off', FALSE, ['sprintf' => [$rootUrl]] ), 'ipsMessage ipsMessage_warning' );
$form->addMessage( Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_off', FALSE, ['sprintf' => [$rootUrl]] ), 'ipsMessage ipsMessage--warning' );
}
else
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_download', FALSE, ['sprintf' => [$rootUrl]] ), 'ipsMessage ipsMessage_warning' );
$form->addMessage( Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_download', FALSE, ['sprintf' => [$rootUrl]] ), 'ipsMessage ipsMessage--warning' );
}
}
else if ( ! \IPS\CIC2 AND file_exists( \IPS\ROOT_PATH . '/robots.txt' ) )
else if ( ! CIC2 AND file_exists( \IPS\ROOT_PATH . '/robots.txt' ) )
{
if ( \IPS\Settings::i()->robots_txt === 'off' )
if ( Settings::i()->robots_txt === 'off' )
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_existing_off', FALSE, ['sprintf' => [ rtrim( \IPS\Http\Url::baseUrl(), '/' ) ] ] ), 'ipsMessage ipsMessage_warning' );
$form->addMessage( Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_existing_off', FALSE, ['sprintf' => [ rtrim( Url::baseUrl(), '/' ) ] ] ), 'ipsMessage ipsMessage--warning' );
}
else
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_existing_download', FALSE, ['sprintf' => [ rtrim( \IPS\Http\Url::baseUrl(), '/' ) ] ] ), 'ipsMessage ipsMessage_warning' );
$form->addMessage( Member::loggedIn()->language()->addToStack( 'use_robotstxt_warning_existing_download', FALSE, ['sprintf' => [ rtrim( Url::baseUrl(), '/' ) ] ] ), 'ipsMessage ipsMessage--warning' );
}
}
}
$form->add( new \IPS\Helpers\Form\Radio( 'use_robotstxt', $value, FALSE, [
$form->add( new Radio( 'use_robotstxt', $value, FALSE, [
'options' => [
'off' => 'use_robotstxt_off',
'default' => 'use_robotstxt_default',
@@ -187,9 +224,7 @@ class _seo extends \IPS\Dispatcher\Controller
]
], NULL, NULL, NULL, 'use_robotstxt' ) );
$form->add( new \IPS\Helpers\Form\Codemirror( 'use_robotstxt_custom_editor', ( $value === 'custom' ? \IPS\Settings::i()->robots_txt : '' ), FALSE, [], NULL, NULL, NULL, 'use_robotstxt_custom_editor' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'seo_reduce_links', \IPS\Settings::i()->seo_reduce_links, TRUE, [], NULL, NULL, NULL, 'seo_reduce_links' ) );
$form->add( new Codemirror( 'use_robotstxt_custom_editor', ( $value === 'custom' ? Settings::i()->robots_txt : '' ), FALSE, [], NULL, NULL, NULL, 'use_robotstxt_custom_editor' ) );
/* Are we saving? */
if ( $values = $form->values() )
@@ -201,11 +236,11 @@ class _seo extends \IPS\Dispatcher\Controller
$value = $values['use_robotstxt_custom_editor'];
}
$form->saveAsSettings( [ 'robots_txt' => $value, 'seo_reduce_links' => $values['seo_reduce_links'] ] );
$form->saveAsSettings( [ 'robots_txt' => $value ] );
\IPS\Session::i()->log( 'acplog__robotstxt_edited' );
Session::i()->log( 'acplog__robotstxt_edited' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&tab=robotstxt&_saved=1" ) );
Output::i()->redirect( Url::internal( "app=core&module=promotion&controller=seo&tab=robotstxt&_saved=1" ) );
}
return $form;
@@ -214,19 +249,20 @@ class _seo extends \IPS\Dispatcher\Controller
/**
* Downloads the robots.txt file
*
* @throws \Exception
* @return void
* @throws Exception
*/
protected function downloadRobotstxt()
protected function downloadRobotstxt() : void
{
if ( \IPS\Settings::i()->robots_txt != 'off' )
if ( Settings::i()->robots_txt != 'off' )
{
if ( \IPS\Settings::i()->robots_txt == 'default' )
if ( Settings::i()->robots_txt == 'default' )
{
\IPS\Output::i()->sendOutput( \IPS\Dispatcher\Front::robotsTxtRules(), 200, 'application/x-robotstxt', array( 'Content-Disposition' => 'attachment; filename=robots.txt' ) );
Output::i()->sendOutput( Front::robotsTxtRules(), 200, 'application/x-robotstxt', array( 'Content-Disposition' => 'attachment; filename=robots.txt' ) );
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Settings::i()->robots_txt, 200, 'application/x-robotstxt', array( 'Content-Disposition' => 'attachment; filename=robots.txt' ) );
Output::i()->sendOutput( Settings::i()->robots_txt, 200, 'application/x-robotstxt', array( 'Content-Disposition' => 'attachment; filename=robots.txt' ) );
}
}
}
@@ -236,32 +272,28 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return string
*/
protected function _manageUrls()
protected function _manageUrls() : string
{
$form = new \IPS\Helpers\Form;
$form = new Form;
$form->add( new \IPS\Helpers\Form\YesNo( 'use_friendly_urls', \IPS\Settings::i()->use_friendly_urls, TRUE, array( 'togglesOn' => array( 'htaccess_mod_rewrite', 'seo_r_on' ), 'togglesOff' => array( 'use_friendly_urls_warning' ) ), NULL, NULL, NULL, 'use_friendly_urls' ) );
$form->add( new YesNo( 'use_friendly_urls', Settings::i()->use_friendly_urls, TRUE, array( 'togglesOn' => array( 'htaccess_mod_rewrite', 'seo_r_on' ), 'togglesOff' => array( 'use_friendly_urls_warning' ) ), NULL, NULL, NULL, 'use_friendly_urls' ) );
static::htaccessSetting( $form );
$form->add( new \IPS\Helpers\Form\YesNo( 'seo_r_on', \IPS\Settings::i()->seo_r_on, TRUE, array( 'togglesOff' => array( 'seo_r_on_warning' ) ), NULL, NULL, NULL, 'seo_r_on' ) );
$form->add( new YesNo( 'seo_r_on', Settings::i()->seo_r_on, TRUE, array( 'togglesOff' => array( 'seo_r_on_warning' ) ), NULL, NULL, NULL, 'seo_r_on' ) );
/* Are we saving? */
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Member::clearCreateMenu();
/* Clear front navigation data store, otherwise it could still contain the non-rewrite furl for some items */
unset( \IPS\Data\Store::i()->frontNavigation );
unset( Store::i()->frontNavigation );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__seo_furl_settings' );
Session::i()->log( 'acplogs__seo_furl_settings' );
/* Clear Sidebar Caches */
\IPS\Widget::deleteCaches();
Widget::deleteCaches();
}
return $form;
@@ -272,22 +304,18 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return string
*/
protected function _manageSitemap()
protected function _manageSitemap() : string
{
/* Init */
$form = new \IPS\Helpers\Form;
$form->addMessage( 'sitemap_blurb', 'ipsMessage ipsMessage_info' );
if( !\IPS\CIC )
{
$form->add( new \IPS\Helpers\Form\Url( 'sitemap_url', \IPS\Settings::i()->sitemap_url ?: \IPS\Settings::i()->base_url . 'sitemap.php', FALSE ) );
}
$form = new Form;
$form->add( new FormUrl( 'sitemap_url', Settings::i()->sitemap_url ?: Settings::i()->base_url . 'sitemap.php', FALSE ) );
/* Get extension settings */
$useRecommendedSettings = TRUE;
$extraSettings = array();
$toggles = array();
$recommendedSettings = array();
foreach ( \IPS\Application::allExtensions( 'core', 'Sitemap', FALSE, 'core' ) as $extKey => $extension )
foreach ( Application::allExtensions( 'core', 'Sitemap', FALSE, 'core' ) as $extKey => $extension )
{
$toggles[] = "form_header_sitemap_{$extKey}";
$recommendedSettings = array_merge( $recommendedSettings, $extension->recommendedSettings );
@@ -304,7 +332,7 @@ class _seo extends \IPS\Dispatcher\Controller
}
/* Build form */
$form->add( new \IPS\Helpers\Form\YesNo( 'sitemap_configuration_info', $useRecommendedSettings, FALSE, array( 'togglesOff' => $toggles ) ) );
$form->add( new YesNo( 'sitemap_configuration_info', $useRecommendedSettings, FALSE, array( 'togglesOff' => $toggles ) ) );
foreach ( $extraSettings as $header => $settings )
{
$form->addHeader( 'sitemap_' . $header );
@@ -317,57 +345,47 @@ class _seo extends \IPS\Dispatcher\Controller
/* Are we saving? */
if ( $values = $form->values() )
{
if( $values[ 'sitemap_configuration_info' ] )
if ( $values['sitemap_configuration_info'] )
{
$values = array_merge( $values, $recommendedSettings );
}
if( !\IPS\CIC )
{
try
{
if( !( $values[ 'sitemap_url' ] instanceof \IPS\Http\Url ) )
{
throw new \RuntimeException;
}
$response = $values[ 'sitemap_url' ]->setQueryString( 'testsettings', 1 )->request()->get();
if( $response->httpResponseCode != 200 or !mb_strpos( $values[ 'sitemap_url' ], 'sitemap.php' ) )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'invalid_sitemap_url' );
}
}
catch( \RuntimeException $e )
try
{
if( !( $values['sitemap_url'] instanceof Url ) )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'form_url_bad' );
throw new RuntimeException;
}
$response = $values['sitemap_url']->setQueryString( 'testsettings', 1 )->request()->get();
if ( $response->httpResponseCode != 200 or !mb_strpos( $values['sitemap_url'], "sitemap.php" ) )
{
$form->error = Member::loggedIn()->language()->addToStack( 'invalid_sitemap_url' );
}
}
catch ( RuntimeException $e )
{
$form->error = Member::loggedIn()->language()->addToStack( 'form_url_bad' );
}
if( !$form->error )
{
if( isset( $values[ 'sitemap_url' ] ) )
$values['sitemap_url'] = (string) $values['sitemap_url'];
foreach( Application::allExtensions( 'core', 'Sitemap', FALSE, 'core' ) as $extKey => $extension )
{
$values['sitemap_url'] = (string) $values['sitemap_url'];
$extension->saveSettings( $values );
}
$form->saveAsSettings( array( 'sitemap_url' => $values['sitemap_url'] ) );
foreach( \IPS\Application::allExtensions( 'core', 'Sitemap', FALSE, 'core' ) as $extKey => $extension )
{
if( method_exists( $extension, 'saveSettings' ) )
{
$extension->saveSettings( $values );
}
}
if( !\IPS\CIC )
{
$form->saveAsSettings( ['sitemap_url' => $values[ 'sitemap_url' ]] );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__seo_sitemap_settings' );
Session::i()->log( 'acplogs__seo_sitemap_settings' );
}
}
return $form;
return Theme::i()->getTemplate( 'forms' )->blurb( 'sitemap_blurb', true, true ) . $form;
}
/**
@@ -375,59 +393,59 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return string
*/
protected function _manageMetatags()
protected function _manageMetatags() : string
{
/* Are we deleting? */
if ( isset( \IPS\Request::i()->delete ) )
if ( isset( Request::i()->delete ) )
{
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
if( isset( \IPS\Request::i()->root ) )
if( isset( Request::i()->root ) )
{
$meta = \IPS\Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', (int) \IPS\Request::i()->root ) )->first();
$tags = array_diff_key( json_decode( $meta['meta_tags'], TRUE ), array( \IPS\Request::i()->delete => 1 ) );
$meta = Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', (int) Request::i()->root ) )->first();
$tags = array_diff_key( json_decode( $meta['meta_tags'], TRUE ), array( Request::i()->delete => 1 ) );
\IPS\Db::i()->update( 'core_seo_meta', array( 'meta_tags' => json_encode( $tags ) ), array( 'meta_id=?', (int) \IPS\Request::i()->root ) );
Db::i()->update( 'core_seo_meta', array( 'meta_tags' => json_encode( $tags ) ), array( 'meta_id=?', (int) Request::i()->root ) );
}
else
{
\IPS\Db::i()->delete( 'core_seo_meta', array( "meta_id=?", (int) \IPS\Request::i()->delete ) );
Db::i()->delete( 'core_seo_meta', array( "meta_id=?", (int) Request::i()->delete ) );
}
unset( \IPS\Data\Store::i()->metaTags );
unset( Store::i()->metaTags );
if ( \IPS\Request::i()->isAjax() )
if ( Request::i()->isAjax() )
{
return;
return '';
}
}
/* Show tree */
$url = \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&tab=metatags" );
$output = new \IPS\Helpers\Tree\Tree(
$url = Url::internal( "app=core&module=promotion&controller=seo&tab=metatags" );
$output = new Tree(
$url,
\IPS\Member::loggedIn()->language()->addToStack('seo_tab_metatags'),
Member::loggedIn()->language()->addToStack('seo_tab_metatags'),
/* Get Roots */
function() use ( $url )
{
$rows = array();
foreach ( \IPS\Db::i()->select( '*', 'core_seo_meta' ) as $row )
foreach ( Db::i()->select( '*', 'core_seo_meta' ) as $row )
{
$urlToDisplay = \IPS\Theme::i()->getTemplate( 'promotion' )->metaTagUrl( trim( $row['meta_url'], '/' ) );
$urlToDisplay = Theme::i()->getTemplate( 'promotion' )->metaTagUrl( trim( $row['meta_url'], '/' ) );
$rows[ $row['meta_url'] ] = \IPS\Theme::i()->getTemplate( 'trees' )->row( $url, $row['meta_id'], $urlToDisplay, TRUE, array(
$rows[ $row['meta_url'] ] = Theme::i()->getTemplate( 'trees' )->row( $url, $row['meta_id'], $urlToDisplay, TRUE, array(
'edit' => array(
'icon' => 'pencil',
'title' => 'seo_meta_manage',
'link' => \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&do=addMeta&id=" . $row['meta_id'] ),
'link' => Url::internal( "app=core&module=promotion&controller=seo&do=addMeta&id=" . $row['meta_id'] ),
'hotkey' => 'e'
),
'delete' => array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&tab=metatags&delete=" . $row['meta_id'] ),
'link' => Url::internal( "app=core&module=promotion&controller=seo&tab=metatags&delete=" . $row['meta_id'] ),
'data' => array( 'delete' => '' )
)
), "", NULL, NULL, FALSE, NULL, NULL, NULL, TRUE );
@@ -438,19 +456,19 @@ class _seo extends \IPS\Dispatcher\Controller
/* Get Row */
function( $key, $root=FALSE ) use ( $url )
{
$meta = \IPS\Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', $key ) )->first();
$meta = Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', $key ) )->first();
return \IPS\Theme::i()->getTemplate( 'trees' )->row( $url, $key, $meta['meta_url'], TRUE, array(
return Theme::i()->getTemplate( 'trees' )->row( $url, $key, $meta['meta_url'], TRUE, array(
'edit' => array(
'icon' => 'pencil',
'title' => 'seo_meta_manage',
'link' => \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&do=addMeta&id=" . $key ),
'link' => Url::internal( "app=core&module=promotion&controller=seo&do=addMeta&id=" . $key ),
'hotkey' => 'e'
),
'delete' => array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&tab=metatags&delete=" . $key ),
'link' => Url::internal( "app=core&module=promotion&controller=seo&tab=metatags&delete=" . $key ),
'data' => array( 'delete' => '' )
)
), '', NULL, NULL, $root );
@@ -463,22 +481,22 @@ class _seo extends \IPS\Dispatcher\Controller
/* Get Children */
function( $key ) use ( $url )
{
$meta = \IPS\Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', $key ) )->first();
$meta = Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', $key ) )->first();
$tags = json_decode( $meta['meta_tags'], TRUE );
$rows = array();
if( \is_array( $tags ) )
if( is_array( $tags ) )
{
foreach ( $tags as $name => $content )
{
$rows[] = \IPS\Theme::i()->getTemplate( 'trees' )->row( $url, $meta['meta_id'] . '-' . $name, $name, FALSE, array(
$rows[] = Theme::i()->getTemplate( 'trees' )->row( $url, $meta['meta_id'] . '-' . $name, $name, FALSE, array(
'delete' => array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( $url . "&root={$key}&delete={$name}" ),
'link' => Url::internal( $url . "&root={$key}&delete={$name}" ),
'data' => array( 'delete' => '' )
)
), $content ?? \IPS\Member::loggedIn()->language()->addToStack('meta_tag_acp_deleted') );
), $content ?? Member::loggedIn()->language()->addToStack('meta_tag_acp_deleted') );
}
}
@@ -491,12 +509,12 @@ class _seo extends \IPS\Dispatcher\Controller
'add' => array(
'icon' => 'plus',
'title' => 'seo_meta_add',
'link' => \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&do=addMeta" ),
'link' => Url::internal( "app=core&module=promotion&controller=seo&do=addMeta" ),
),
'launch' => array(
'icon' => 'magic',
'title' => 'metatag_live_editor',
'link' => \IPS\Http\Url::internal( "app=core&module=system&controller=metatags", "front" ),
'link' => Url::internal( "app=core&module=system&controller=metatags", "front" ),
'target' => '_blank'
),
);
@@ -507,9 +525,9 @@ class _seo extends \IPS\Dispatcher\Controller
);
/* Output or return */
if ( ! \IPS\Request::i()->isAjax() )
if ( ! Request::i()->isAjax() )
{
$output = \IPS\Theme::i()->getTemplate( 'forms' )->blurb( "what_is_a_metatag", TRUE, TRUE ) . $output;
$output = Theme::i()->getTemplate( 'forms' )->blurb( "what_is_a_metatag", TRUE, TRUE ) . $output;
}
return $output;
@@ -520,36 +538,36 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function addMeta()
public function addMeta() : void
{
$url = NULL;
$tags = array();
$title = NULL;
/* If we have a URL, load up the existing tags for it as we are "editing" */
if( isset( \IPS\Request::i()->id ) )
if( isset( Request::i()->id ) )
{
$meta = \IPS\Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', (int) \IPS\Request::i()->id ) )->first();
$meta = Db::i()->select( '*', 'core_seo_meta', array( 'meta_id=?', (int) Request::i()->id ) )->first();
$tags = json_decode( $meta['meta_tags'], TRUE );
$url = $meta['meta_url'];
$title = $meta['meta_title'];
}
$form = new \IPS\Helpers\Form;
$form->class = 'ipsForm_vertical ipsPad';
$form->add( new \IPS\Helpers\Form\Text( 'metatag_url', $url, FALSE, array( 'placeholder' => 'profile/*' ), NULL, \IPS\Settings::i()->base_url ) );
$form = new Form;
$form->class = 'ipsForm--vertical ipsForm--add-meta i-padding_3';
$form->add( new Text( 'metatag_url', $url, FALSE, array( 'placeholder' => 'profile/*' ), NULL, Settings::i()->base_url ) );
$form->hiddenValues['original_url'] = $url;
$form->add( new \IPS\Helpers\Form\Text( 'metatag_title', $title, FALSE ) );
$form->add( new Text( 'metatag_title', $title, FALSE ) );
/* Now add the rows */
$matrix = new \IPS\Helpers\Form\Matrix();
$matrix = new Matrix();
$matrix->manageable = TRUE;
$matrix->langPrefix = 'metatags_';
$matrix->columns = array(
'name' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Select( $key,
return new Select( $key,
$data ? $data['name'] : '',
TRUE,
array( 'options' => array( 'keywords' => 'meta_keywords', 'description' => 'meta_description', 'robots' => 'meta_robots', 'other' => 'meta_other' ), 'toggles' => array( 'other' => array( 'other_' . preg_replace( "/[^a-zA-Z0-9\-_]/", "_", $key ) ) ), 'userSuppliedInput' => 'other' ),
@@ -561,12 +579,12 @@ class _seo extends \IPS\Dispatcher\Controller
},
'content' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\TextArea( $key, $data ? $data['content'] : '', FALSE, array( 'nullLang' => 'meta_tag_null_acp_form' ) );
return new TextArea( $key, $data ? $data['content'] : '', FALSE, array( 'nullLang' => 'meta_tag_null_acp_form' ) );
},
);
/* Add rows */
if( \count( $tags ) )
if( count( $tags ) )
{
foreach( $tags as $tagName => $tagValue )
{
@@ -593,27 +611,24 @@ class _seo extends \IPS\Dispatcher\Controller
$tags[ $data['name'] ] = $data['content'];
}
\IPS\Db::i()->delete( 'core_seo_meta', array( 'meta_url=?', $url ) );
\IPS\Db::i()->delete( 'core_seo_meta', array( 'meta_url=?', \IPS\Request::i()->original_url ) );
Db::i()->delete( 'core_seo_meta', array( 'meta_url=?', $url ) );
Db::i()->delete( 'core_seo_meta', array( 'meta_url=?', Request::i()->original_url ) );
if( $title or \count( $tags ) )
if( $title or count( $tags ) )
{
\IPS\Db::i()->insert( 'core_seo_meta', array( 'meta_url' => $url, 'meta_title' => $title, 'meta_tags' => json_encode( $tags ) ) );
Db::i()->insert( 'core_seo_meta', array( 'meta_url' => $url, 'meta_title' => $title, 'meta_tags' => json_encode( $tags ) ) );
}
\IPS\Session::i()->log( 'acplogs__seo_metatag_settings' );
Session::i()->log( 'acplogs__seo_metatag_settings' );
unset( \IPS\Data\Store::i()->metaTags );
unset( Store::i()->metaTags );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo&tab=metatags" ) );
Output::i()->redirect( Url::internal( "app=core&module=promotion&controller=seo&tab=metatags" ) );
}
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'promotion/meta.css', 'core', 'admin' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('seo_meta_add');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'seo_meta_add', $form );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'promotion/meta.css', 'core', 'admin' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('seo_meta_add');
Output::i()->output = Theme::i()->getTemplate( 'global' )->block( 'seo_meta_add', $form );
}
/**
@@ -621,12 +636,12 @@ class _seo extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function htaccess()
protected function htaccess() : void
{
$dir = str_replace( \IPS\CP_DIRECTORY . '/index.php', '', $_SERVER['PHP_SELF'] );
$dir = str_replace( 'admin/index.php', '', $_SERVER['PHP_SELF'] );
$path = $dir . 'index.php';
if( \strpos( $dir, ' ' ) !== FALSE )
if( strpos( $dir, ' ' ) !== FALSE )
{
$dir = '"' . $dir . '"';
$path = '"' . $path . '"';
@@ -646,26 +661,26 @@ RewriteRule . {$path} [L]
</IfModule>
FILE;
\IPS\Output::i()->sendOutput( $htaccess, 200, 'application/x-htaccess', array( 'Content-Disposition' => 'attachment; filename=.htaccess' ) );
Output::i()->sendOutput( $htaccess, 200, 'application/x-htaccess', array( 'Content-Disposition' => 'attachment; filename=.htaccess' ) );
}
/**
* Trigger the sitemap rebuild
*/
protected function rebuildSitemap()
protected function rebuildSitemap() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
/* truncate sitemap */
\IPS\Db::i()->delete( 'core_sitemap' );
Db::i()->delete( 'core_sitemap' );
$extensions = \IPS\Application::allExtensions( 'core', 'Sitemap', new \IPS\Member, 'core' );
$extensions = Application::allExtensions( 'core', 'Sitemap', new Member, 'core' );
foreach ( $extensions as $k => $extension )
{
\IPS\Task::queue( 'core', 'RebuildSitemap', array( 'extensionKey' => $k ), 5 );
Task::queue( 'core', 'RebuildSitemap', array( 'extensionKey' => $k ), 5 );
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=promotion&controller=seo" ), 'rebuild_sitemap_initialized' );
Output::i()->redirect( Url::internal( "app=core&module=promotion&controller=seo" ), 'rebuild_sitemap_initialized' );
}
}
@@ -11,43 +11,57 @@
namespace IPS\core\modules\admin\promotion;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\ShareServices;
use IPS\core\ShareLinks\Service;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Http\Url;
use IPS\Node\Controller;
use IPS\Node\Model;
use IPS\Output;
use IPS\Request;
use OutOfRangeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Share Link Services
*/
class _sharelinks extends \IPS\Node\Controller
class sharelinks extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Node Class
*/
protected $nodeClass = '\IPS\core\ShareLinks\Service';
protected string $nodeClass = '\IPS\core\ShareLinks\Service';
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'sharelinks_manage' );
Dispatcher::i()->checkAcpPermission( 'sharelinks_manage' );
$reloadRoots = FALSE;
/* First, see if any are missing */
$nodeClass = $this->nodeClass;
$shareServices = \IPS\Content\ShareServices::services();
$shareServices = ShareServices::services();
/* @var Model $nodeClass */
foreach( $nodeClass::roots() as $node )
{
if( !isset( $shareServices[ ucwords( $node->key ) ] ) )
@@ -58,16 +72,16 @@ class _sharelinks extends \IPS\Node\Controller
}
/* Now see if there are any new classes */
foreach( \IPS\Content\ShareServices::services() as $id => $className )
foreach( ShareServices::services() as $id => $className )
{
try
{
$nodeClass::load( mb_strtolower( $id ), 'share_key' );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
/* Class does not exist - let's add it */
$newService = new \IPS\core\ShareLinks\Service;
$newService = new Service;
$newService->key = mb_strtolower( $id );
$newService->groups = '*';
$newService->title = $id;
@@ -83,7 +97,7 @@ class _sharelinks extends \IPS\Node\Controller
$nodeClass::resetRootResult();
}
return parent::execute();
parent::execute();
}
/**
@@ -91,7 +105,7 @@ class _sharelinks extends \IPS\Node\Controller
*
* @return array
*/
public function _getRootButtons()
public function _getRootButtons(): array
{
return array();
}
@@ -101,16 +115,13 @@ class _sharelinks extends \IPS\Node\Controller
*
* @return void
*/
public function delete()
public function delete() : void
{
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
\IPS\Db::i()->delete( 'core_share_links', array( 'share_id=?', (int) \IPS\Request::i()->id ) );
Db::i()->delete( 'core_share_links', array( 'share_id=?', (int) Request::i()->id ) );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=promotion&controller=sharelinks' ), 'saved' );
Output::i()->redirect( Url::internal( 'app=core&module=promotion&controller=sharelinks' ), 'saved' );
}
}