Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,820 @@
<?php
/**
* @brief Advanced Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 10 June 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* Advanced Settings
*/
class _advanced extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage' );
parent::execute();
}
/**
* Manage: Works out tab and fetches content
*
* @return void
*/
protected function manage()
{
/* Work out output */
\IPS\Request::i()->tab = isset( \IPS\Request::i()->tab ) ? \IPS\Request::i()->tab : 'settings';
if ( $pos = mb_strpos( \IPS\Request::i()->tab, '-' ) )
{
$activeTabContents = call_user_func( array( $this, '_manage'.ucfirst( mb_substr( \IPS\Request::i()->tab, 0, $pos ) ) ), mb_substr( \IPS\Request::i()->tab, $pos + 1 ) );
}
else
{
$activeTabContents = call_user_func( array( $this, '_manage'.ucfirst( \IPS\Request::i()->tab ) ) );
}
/* 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['settings'] = 'server_environment';
if ( \IPS\Settings::i()->use_friendly_urls )
{
$tabs['furl'] = 'furls';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'datastore' ) )
{
$tabs['datastore'] = 'data_store';
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_settings_advanced');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->tabs( $tabs, \IPS\Request::i()->tab, $activeTabContents, \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced" ) );
}
/**
* Data store management
*
* @return string
*/
protected function _manageDatastore()
{
/* Are we just checking the constants? */
if ( isset( \IPS\Request::i()->checkConstants ) )
{
/* If we've changed anything, explain to the admin they have to update */
if ( \IPS\Request::i()->store_method !== \IPS\STORE_METHOD or \IPS\Request::i()->store_config !== \IPS\STORE_CONFIG or \IPS\Request::i()->cache_method !== \IPS\CACHE_METHOD or \IPS\Request::i()->cache_config !== \IPS\CACHE_CONFIG or \IPS\Request::i()->cache_guest_page != \IPS\CACHE_PAGE_TIMEOUT )
{
$downloadUrl = \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=downloadDatastoreConstants' )->setQueryString( array( 'store_method' => \IPS\Request::i()->store_method, 'store_config' => \IPS\Request::i()->store_config, 'cache_method' => \IPS\Request::i()->cache_method, 'cache_config' => \IPS\Request::i()->cache_config, 'cache_guest_page' => \IPS\Request::i()->cache_guest_page ) );
$checkUrl = \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=datastore&checkConstants=1' )->setQueryString( array( 'store_method' => \IPS\Request::i()->store_method, 'store_config' => \IPS\Request::i()->store_config, 'cache_method' => \IPS\Request::i()->cache_method, 'cache_config' => \IPS\Request::i()->cache_config, 'cache_guest_page' => \IPS\Request::i()->cache_guest_page ) );
return \IPS\Theme::i()->getTemplate( 'settings' )->dataStoreChange( $downloadUrl, $checkUrl, TRUE );
}
/* Otherwise just log and redirect */
else
{
/* Clear it */
\IPS\Data\Cache::i()->clearAll();
\IPS\Data\Store::i()->clearAll();
/* Enable/disable the clearcaches task */
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => intval( \IPS\CACHE_METHOD === 'None' and \IPS\CACHE_PAGE_TIMEOUT ) ), "`key`='clearcache'" );
/* Log and redirect */
\IPS\Session::i()->log( 'acplogs__datastore_settings_updated' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=datastore' ), 'saved' );
}
}
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'datastore' );
/* Init */
$form = new \IPS\Helpers\Form;
/* Cold storage */
$extra = array();
$toggles = array();
$disabled = array();
$storeConfigurationFields = array();
$options = array(
'FileSystem' => 'datastore_method_FileSystem',
'Database' => 'datastore_method_Database',
);
$existingConfiguration = json_decode( \IPS\STORE_CONFIG, TRUE );
foreach ( $options as $k => $v )
{
$class = 'IPS\Data\Store\\' . $k;
if ( !$class::supported() )
{
$disabled[] = $k;
\IPS\Member::loggedIn()->language()->words["datastore_method_{$k}_desc"] = \IPS\Member::loggedIn()->language()->addToStack('datastore_method_disableddesc', FALSE, array( 'sprintf' => array( $k ) ) );
}
else
{
foreach ( $class::configuration( $k === \IPS\STORE_METHOD ? $existingConfiguration : array() ) as $inputKey => $input )
{
if ( !$input->htmlId )
{
$input->htmlId = md5( uniqid() );
}
$extra[] = $input;
$toggles[ $k ][] = $input->htmlId;
$storeConfigurationFields[ $k ][ $inputKey ] = $input->name;
}
}
}
$form->add( new \IPS\Helpers\Form\Radio( 'datastore_method', \IPS\STORE_METHOD, TRUE, array(
'options' => $options,
'toggles' => $toggles,
'disabled' => $disabled,
) ) );
foreach ( $extra as $input )
{
$form->add( $input );
}
/* Cache */
$extra = array();
$toggles = array();
$disabled = array();
$cacheConfigurationFields = array();
$options = array(
'None' => 'datastore_method_None',
'Apc' => 'datastore_method_Apc',
'Eaccelerator' => 'datastore_method_Eaccelerator',
'Memcache' => 'datastore_method_Memcache',
'Redis' => 'datastore_method_Redis',
'Wincache' => 'datastore_method_Wincache',
'Xcache' => 'datastore_method_Xcache',
);
if ( \IPS\TEST_CACHING )
{
$options['Test'] = 'datastore_method_Test';
}
$existingConfiguration = json_decode( \IPS\CACHE_CONFIG, TRUE );
foreach ( $options as $k => $v )
{
$class = 'IPS\Data\Cache\\' . $k;
if ( !$class::supported() )
{
$disabled[] = $k;
\IPS\Member::loggedIn()->language()->words["datastore_method_{$k}_desc"] = \IPS\Member::loggedIn()->language()->addToStack('datastore_method_disableddesc', FALSE, array( 'sprintf' => array( $k ) ) );
}
else
{
foreach ( $class::configuration( $k === \IPS\CACHE_METHOD ? $existingConfiguration : array() ) as $inputKey => $input )
{
if ( !$input->htmlId )
{
$input->htmlId = md5( uniqid() );
}
$extra[] = $input;
$toggles[ $k ][] = $input->htmlId;
$cacheConfigurationFields[ $k ][ $inputKey ] = $input->name;
}
}
}
$form->add( new \IPS\Helpers\Form\Radio( 'cache_method', \IPS\CACHE_METHOD, TRUE, array(
'options' => $options,
'toggles' => $toggles,
'disabled' => $disabled,
) ) );
foreach ( $extra as $input )
{
$form->add( $input );
}
$form->add( new \IPS\Helpers\Form\Number( 'cache_guest_page', \IPS\CACHE_PAGE_TIMEOUT, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'disable' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('for'), \IPS\Member::loggedIn()->language()->addToStack('seconds'), 'cache_guest_page' ) );
/* Handle submissions */
if ( $values = $form->values() )
{
/* Work out configuration */
$storeConfiguration = array();
if ( isset( $storeConfigurationFields[ $values['datastore_method'] ] ) )
{
foreach ( $storeConfigurationFields[ $values['datastore_method'] ] as $k => $fieldName )
{
$storeConfiguration[ $k ] = $values[ $fieldName ];
}
}
$cacheConfiguration = array();
if ( isset( $cacheConfigurationFields[ $values['cache_method'] ] ) )
{
foreach ( $cacheConfigurationFields[ $values['cache_method'] ] as $k => $fieldName )
{
$cacheConfiguration[ $k ] = $values[ $fieldName ];
}
}
/* If we've changed anything, explain to the admin they have to update */
if ( $values['datastore_method'] !== \IPS\STORE_METHOD or str_replace( '\\/', '/', json_encode( $storeConfiguration ) ) !== \IPS\STORE_CONFIG or $values['cache_method'] !== \IPS\CACHE_METHOD or json_encode( $cacheConfiguration ) !== \IPS\CACHE_CONFIG or $values['cache_guest_page'] !== \IPS\CACHE_PAGE_TIMEOUT )
{
/* Connect to cache engine if we can and invalidate any existing caches */
try
{
$classname = 'IPS\Data\Cache\\' . $values['cache_method'];
if ( $classname::supported() )
{
$instance = new $classname( $cacheConfiguration );
$instance->clearAll();
}
}
catch( \Exception $e ){}
/* Enable/disable the clearcaches task */
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => intval( $values['cache_method'] === 'None' and $values['cache_guest_page'] ) ), "`key`='clearcache'" );
/* Display */
$downloadUrl = \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=downloadDatastoreConstants' )->setQueryString( array( 'store_method' => $values['datastore_method'], 'store_config' => str_replace( '\\/', '/', json_encode( $storeConfiguration ) ), 'cache_method' => $values['cache_method'], 'cache_config' => json_encode( $cacheConfiguration ), 'cache_guest_page' => $values['cache_guest_page'] ) );
$checkUrl = \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=datastore&checkConstants=1' )->setQueryString( array( 'store_method' => $values['datastore_method'], 'store_config' => str_replace( '\\/', '/', json_encode( $storeConfiguration ) ), 'cache_method' => $values['cache_method'], 'cache_config' => json_encode( $cacheConfiguration ), 'cache_guest_page' => $values['cache_guest_page'] ) );
return \IPS\Theme::i()->getTemplate( 'settings' )->dataStoreChange( $downloadUrl, $checkUrl );
}
/* Otherwise just log and redirect */
else
{
\IPS\Session::i()->log( 'acplogs__datastore_settings_updated' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=datastore' ), 'saved' );
}
}
return $form;
}
/**
* Download constants.php
*
* @return void
*/
protected function downloadDatastoreConstants()
{
$output = "<?php\n\n";
foreach ( \IPS\IPS::defaultConstants() as $k => $v )
{
$val = constant( 'IPS\\' . $k );
if ( $val !== $v and !in_array( $k, array( 'STORE_METHOD', 'STORE_CONFIG', 'CACHE_METHOD', 'CACHE_CONFIG', 'CACHE_PAGE_TIMEOUT', 'SUITE_UNIQUE_KEY' ) ) )
{
$output .= "define( '{$k}', " . var_export( $val, TRUE ) . " );\n";
}
}
$output .= "\n";
$output .= "define( 'STORE_METHOD', " . var_export( \IPS\Request::i()->store_method, TRUE ) . " );\n";
$output .= "define( 'STORE_CONFIG', " . var_export( \IPS\Request::i()->store_config, TRUE ) . " );\n";
$output .= "define( 'CACHE_METHOD', " . var_export( \IPS\Request::i()->cache_method, TRUE ) . " );\n";
$output .= "define( 'CACHE_CONFIG', " . var_export( \IPS\Request::i()->cache_config, TRUE ) . " );\n";
$output .= "define( 'CACHE_PAGE_TIMEOUT', " . var_export( (int) \IPS\Request::i()->cache_guest_page, TRUE ) . " );\n";
$output .= "define( 'SUITE_UNIQUE_KEY', " . var_export( mb_substr( md5( uniqid() ), 10, 10 ), TRUE ) . " );\n"; // Regenerate the unique key so there's no conflicts
$output .= "\n\n\n";
\IPS\Output::i()->sendOutput( $output, 200, 'text/x-php', array( 'Content-Disposition' => 'attachment; filename=constants.php' ) );
}
/**
* Settings
*
* @return string
*/
protected function _manageSettings()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_server' );
/* Generate a cron key if we don't have one */
if ( !\IPS\Settings::i()->task_cron_key )
{
\IPS\Settings::i()->task_cron_key = md5( uniqid() );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Settings::i()->task_cron_key ), array( 'conf_key=?', 'task_cron_key' ) );
unset( \IPS\Data\Store::i()->settings );
}
/* Sort stuff out for the cron setting */
\IPS\Member::loggedIn()->language()->words['task_use_cron_warning'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'task_use_cron_warning', FALSE ), PHP_BINDIR . '/php -d memory_limit=-1 -d max_execution_time=0 ' . \IPS\ROOT_PATH . '/applications/core/interface/task/task.php ' . \IPS\Settings::i()->task_cron_key );
$cronOptions = array( 'togglesOn' => array( 'task_use_cron_warning' ) );
/* Build and show form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\YesNo( 'task_use_cron', \IPS\Settings::i()->task_use_cron, FALSE, $cronOptions, function ( $val )
{
$cronFile = \IPS\ROOT_PATH . '/applications/core/interface/task/task.php';
if ( $val and ( mb_strtoupper( mb_substr( PHP_OS, 0, 3 ) ) !== 'WIN' AND !is_executable( $cronFile ) ) )
{
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('task_use_cron_executable', FALSE, array( 'sprintf' => array( $cronFile ) ) ) );
}
}, NULL, NULL, 'task_use_cron' ) );
$form->add( new \IPS\Helpers\Form\Number( 'widget_cache_ttl', ( isset( \IPS\Settings::i()->widget_cache_ttl ) ) ? \IPS\Settings::i()->widget_cache_ttl : 60, FALSE, array( 'min' => 60 ), NULL, \IPS\Member::loggedIn()->language()->addToStack('for'), \IPS\Member::loggedIn()->language()->addToStack('seconds') ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__advanced_server_edited' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=settings' ), 'saved' );
}
return $form;
}
/**
* Tasks
*
* @return void
*/
protected function tasks()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_tasks' );
$table = new \IPS\Helpers\Table\Db( 'core_tasks', \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=tasks' ) );
$table->langPrefix = 'task_manager_';
$table->include = array( 'app', 'key', 'frequency', 'next_run' );
$table->mainColumn = 'key';
$table->quickSearch = 'key';
$table->sortBy = $table->sortBy ?: 'next_run';
$table->sortDirection = $table->sortDirection ?: 'asc';
$table->quickSearch = function( $val )
{
$matches = \IPS\Member::loggedIn()->language()->searchCustom( 'task__', $val, TRUE );
if ( count( $matches ) )
{
return \IPS\Db::i()->in( '`key`', array_keys( $matches ) );
}
else
{
return '1=0';
}
};
$table->parsers = array(
'app' => function( $val, $row )
{
try
{
return $val ? \IPS\Application::load( $val )->_title : \IPS\Plugin::load( $row['plugin'] )->name;
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
},
'key' => function( $val )
{
$langKey = 'task__' . $val;
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( $langKey ) )
{
return $val . '<br><span class="ipsType_light">' . \IPS\Member::loggedIn()->language()->addToStack( $langKey ) . '</span>';
}
return $val;
},
'frequency' => function ( $v )
{
$interval = new \DateInterval( $v );
$return = array();
foreach ( array( 'y' => 'years', 'm' => 'months', 'd' => 'days', 'h' => 'hours', 'i' => 'minutes', 's' => 'seconds' ) as $k => $v )
{
if ( $interval->$k )
{
$return[] = \IPS\Member::loggedIn()->language()->addToStack( 'every_x_' . $v, FALSE, array( 'pluralize' => array( $interval->format( '%' . $k ) ) ) );
}
}
return \IPS\Member::loggedIn()->language()->formatList( $return );
},
'next_run' => function ( $v, $row )
{
if ( !$row['enabled'] )
{
return \IPS\Member::loggedIn()->language()->addToStack('task_manager_disabled');
}
elseif ( $row['running'] )
{
return \IPS\Member::loggedIn()->language()->addToStack('task_manager_running');
}
else
{
return (string) \IPS\DateTime::ts( $row['next_run'] ?: time() );
}
}
);
$table->rowButtons = function( $row )
{
if ( $row['running'] )
{
$return = array( 'unlock' => array(
'icon' => 'unlock',
'title' => 'task_manager_unlock',
'link' => \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced&do=unlockTask&id={$row['id']}" )
) );
}
else
{
$return = array( 'run' => array(
'icon' => 'play-circle',
'title' => 'task_manager_run',
'link' => \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced&do=runTask&id={$row['id']}" )
) );
}
$return['logs'] = array(
'icon' => 'search',
'title' => 'task_manager_logs',
'link' => \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced&do=taskLogs&id={$row['id']}" )
);
return $return;
};
/* Add a button for settings */
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'settings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=taskSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('settings') )
),
);
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('task_manager');
\IPS\Output::i()->output = (string) $table;
}
/**
* Settings
*
* @return void
*/
protected function taskSettings()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Number( 'prune_log_tasks', \IPS\Settings::i()->prune_log_tasks, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days'), 'prune_log_tasks' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__tasklog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=tasks' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('task_settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'task_settings', $form, FALSE );
}
/**
* Run Task
*
* @return void
*/
protected function runTask()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_tasks' );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('task_manager');
try
{
$task = \IPS\Task::load( \IPS\Request::i()->id );
if ( $task->running and !\IPS\IN_DEV )
{
\IPS\Output::i()->error( 'task_manager_locked', '2C124/2', 403, '' );
}
$output = $task->run();
if ( $output === NULL )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=tasks' ), 'task_manager_ran' );
}
else
{
if ( is_array( $output ) )
{
$output = implode( "\n", array_map( array( \IPS\Member::loggedIn()->language(), 'addToStack' ), $output ) );
}
elseif ( !is_string( $output ) and !is_numeric( $output ) )
{
$output = var_export( $output, TRUE );
}
else
{
$output = \IPS\Member::loggedIn()->language()->addToStack( $output, FALSE );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'advancedsettings' )->taskResult( TRUE, $output, $task->id );
}
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C124/1', 404, '' );
}
catch ( \IPS\Task\Exception $e )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'advancedsettings' )->taskResult( FALSE, \IPS\Member::loggedIn()->language()->addToStack( $e->getMessage(), FALSE ), $task->id );
}
}
/**
* Unlock Task
*
* @return void
*/
protected function unlockTask()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_tasks' );
try
{
\IPS\Task::load( \IPS\Request::i()->id )->unlock();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=tasks' ), 'task_manager_unlocked' );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C124/3', 404, '' );
}
}
/**
* View task logs
*
* @return void
*/
protected function taskLogs()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_tasks' );
try
{
$task = \IPS\Task::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C124/4', 404, '' );
}
$table = new \IPS\Helpers\Table\Db( 'core_tasks_log', \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced&do=taskLogs&id={$task->id}" ), array( 'task=?', $task->id ) );
$table->langPrefix = 'task_manager_';
$table->include = array( 'time', 'log' );
$table->parsers = array(
'time' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
},
'log' => function ( $val, $row )
{
$val = json_decode( $val );
if ( is_array( $val ) )
{
$val = implode( "\n", array_map( array( \IPS\Member::loggedIn()->language(), 'addToStack' ), $val ) );
}
elseif ( !is_string( $val ) and !is_numeric( $val ) )
{
$val = var_export( $val, TRUE );
}
else
{
$val = \IPS\Member::loggedIn()->language()->addToStack( $val, FALSE );
}
return $row['error'] ? \IPS\Theme::i()->getTemplate( 'global' )->message( $val, 'error' ) : $val;
}
);
$table->sortBy = $table->sortBy ?: 'time';
$table->quickSearch = 'log';
$table->advancedSearch = array(
'time' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'log' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT
);
\IPS\Output::i()->title = $task->key;
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->message( 'tasklogs_blurb', 'info' ) . $table;
}
/**
* FURLs
*
* @return string
*/
protected function _manageFurl()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_furls' );
if ( \IPS\IN_DEV and !\IPS\DEV_USE_FURL_CACHE )
{
\IPS\Output::i()->error( 'furl_in_dev', '1C124/5', 403, '' );
}
$definition = \IPS\Http\Url::furlDefinition();
$table = new \IPS\Helpers\Table\Custom( $definition, \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=furl' ) );
$table->include = array( 'friendly', 'real' );
$table->langPrefix = 'furl_';
$table->mainColumn = 'real';
$table->parsers = array(
'friendly' => function( $val )
{
$val = preg_replace( '/{[@#](.+?)}/', '<strong><em>$1</em></strong>', $val );
$val = preg_replace( '/{\?(\d+?)?}/', '<em>??</em>', $val );
return "<span class='ipsType_light ipsResponsive_hideTablet'>" . \IPS\Settings::i()->base_url . ( \IPS\Settings::i()->htaccess_mod_rewrite ? '' : 'index.php?/' ) . "</span>{$val}";
},
'real' => function( $val, $row )
{
preg_match_all( '/{([@#])(.+?)}/', $row['friendly'], $matches );
if ( !empty( $matches[0] ) )
{
if ( $val )
{
$val .= '&';
}
foreach ( $matches[0] as $i => $m )
{
$val .= $matches[ 2 ][ $i ] . '=<strong><em>' . ( $matches[ 1 ][ $i ] == '#' ? '123' : 'abc' ) . '</em></strong>';
}
$val .= '</strong>';
}
return "<span class='ipsType_light ipsResponsive_hideTablet'>" . \IPS\Settings::i()->base_url . "index.php?</span>{$val}";
}
);
$table->quickSearch = 'friendly';
$table->advancedSearch = array(
'friendly' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'real' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT
);
$table->rootButtons = array(
'add' => array(
'icon' => 'plus',
'title' => 'add',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=furlForm' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add') )
)
);
if( \IPS\Settings::i()->furl_configuration AND $config = json_decode( \IPS\Settings::i()->furl_configuration, TRUE ) AND count( $config ) )
{
$table->rootButtons['revert'] = array(
'icon' => 'undo',
'title' => 'furl_revert',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&do=furlRevert' ),
'data' => array( 'confirm' => '' )
);
}
$table->rowButtons = function( $row, $k ) use ( $definition )
{
$return = array(
'edit' => array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced&do=furlForm&key={$k}" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit') )
)
);
if( isset( $definition[ $k ]['custom'] ) )
{
$return['delete'] = array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( "app=core&module=settings&controller=advanced&do=furlDelete&key={$k}" ),
'data' => array( 'delete' => '' )
);
}
return $return;
};
return ( \IPS\Request::i()->advancedSearchForm ? '' : \IPS\Theme::i()->getTemplate('global')->message( 'furl_warning', 'warning' ) ) . $table;
}
/**
* Add/Edit FURL
*
* @return void
*/
protected function furlForm()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_furls' );
$current = NULL;
$config = \IPS\Http\Url::furlDefinition();
if ( \IPS\Request::i()->key )
{
$current = ( isset( $config[ \IPS\Request::i()->key ] ) ) ? $config[ \IPS\Request::i()->key ] : NULL;
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'furl_friendly', $current ? $current['friendly'] : '', FALSE, array(), NULL, \IPS\Settings::i()->base_url . ( \IPS\Settings::i()->htaccess_mod_rewrite ? '' : 'index.php?/' ) ) );
$form->add( new \IPS\Helpers\Form\Text( 'furl_real', $current ? $current['real'] : '', FALSE, array(), NULL, \IPS\Settings::i()->base_url . 'index.php?' ) );
if ( $values = $form->values() )
{
$furl = \IPS\Settings::i()->furl_configuration ? json_decode( \IPS\Settings::i()->furl_configuration, TRUE ) : array();
$save = array(
'friendly' => $values['furl_friendly'],
'real' => $values['furl_real'],
'custom' => true
);
if ( \IPS\Request::i()->key )
{
$furl[ \IPS\Request::i()->key ] = $save;
}
else
{
$furl[] = $save;
}
\IPS\Session::i()->log( 'acplogs__advanced_furl_edited' );
$newValue = json_encode( $furl );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $newValue ), array( 'conf_key=?', 'furl_configuration' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear Sidebar Caches */
\IPS\Widget::deleteCaches();
/* Clear create menu caches */
\IPS\Member::clearCreateMenu();
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=furl' ), 'saved' );
}
\IPS\Output::i()->output = $form;
}
/**
* Delete FURL
*
* @return void
*/
protected function furlDelete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_furls' );
$furlDefinition = \IPS\Settings::i()->furl_configuration ? json_decode( \IPS\Settings::i()->furl_configuration, TRUE ) : array();
if( isset( $furlDefinition[ \IPS\Request::i()->key ] ) )
{
unset( $furlDefinition[ \IPS\Request::i()->key ] );
$newValue = json_encode( $furlDefinition );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $newValue ), array( 'conf_key=?', 'furl_configuration' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
}
\IPS\Session::i()->log( 'acplogs__advanced_furl_deleted' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=furl' ), 'saved' );
}
/**
* Revert FURL customisation
*
* @return void
*/
protected function furlRevert()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'advanced_manage_furls' );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => NULL ), array( 'conf_key=?', 'furl_configuration' ) );
unset( \IPS\Data\Store::i()->settings );
unset( \IPS\Data\Store::i()->furl_configuration );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__advanced_furl_reverted' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=advanced&tab=furl' ), 'saved' );
}
}
@@ -0,0 +1,322 @@
<?php
/**
* @brief email
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* email
*/
class _email extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_manage' );
parent::execute();
}
/**
* Email Settings
*
* @return void
*/
protected function manage()
{
/* Build the settings form */
$messageHtml = '';
$settingsForm = new \IPS\Helpers\Form( 'settings_form' );
$settingsForm->addHeader( 'basic_settings' );
$settingsForm->add( new \IPS\Helpers\Form\Email( 'email_out', \IPS\Settings::i()->email_out, TRUE ) );
$settingsForm->add( new \IPS\Helpers\Form\Email( 'email_in', \IPS\Settings::i()->email_in, TRUE ) );
$settingsForm->add( new \IPS\Helpers\Form\Color( 'email_color', \IPS\Settings::i()->email_color, TRUE ) );
$settingsForm->add( new \IPS\Helpers\Form\Upload( 'email_logo', \IPS\Settings::i()->email_logo ? \IPS\File::get( 'core_Theme', \IPS\Settings::i()->email_logo ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Theme' ) ) );
$settingsForm->addHeader( 'advanced_settings' );
$settingsForm->add( new \IPS\Helpers\Form\Select( 'mail_method', \IPS\Settings::i()->mail_method, TRUE, array(
'options' => array( 'mail' => 'mail_method_php', 'smtp' => 'mail_method_smtp' ),
'toggles' => array(
'mail' => array( 'php_mail_extra' ),
'smtp' => array( 'smtp_host', 'smtp_port', 'smtp_user', 'smtp_pass', 'smtp_helo' )
)
) ) );
$settingsForm->add( new \IPS\Helpers\Form\Text( 'smtp_host', \IPS\Settings::i()->smtp_host, FALSE, array(), NULL, NULL, NULL, 'smtp_host' ) );
$settingsForm->add( new \IPS\Helpers\Form\Number( 'smtp_port', \IPS\Settings::i()->smtp_port, FALSE, array(), NULL, NULL, NULL, 'smtp_port' ) );
$settingsForm->add( new \IPS\Helpers\Form\Text( 'smtp_user', \IPS\Settings::i()->smtp_user, FALSE, array(), NULL, NULL, NULL, 'smtp_user' ) );
$settingsForm->add( new \IPS\Helpers\Form\Password( 'smtp_pass', \IPS\Settings::i()->smtp_pass, FALSE, array(), NULL, NULL, NULL, 'smtp_pass' ) );
$settingsForm->add( new \IPS\Helpers\Form\Text( 'php_mail_extra', \IPS\Settings::i()->php_mail_extra, FALSE, array(), NULL, NULL, NULL, 'php_mail_extra' ) );
if ( $values = $settingsForm->values() )
{
$sendTestEmail = FALSE;
foreach( array( 'mail_method', 'smtp_host', 'smtp_port', 'smtp_pass', 'smtp_user', 'php_mail_extra' ) as $setting )
{
if( $values[ $setting ] != \IPS\Settings::i()->$setting )
{
$sendTestEmail = TRUE;
}
}
$settingsForm->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__email_settings' );
if( $sendTestEmail )
{
$email = \IPS\Email::buildFromContent( \IPS\Member::loggedIn()->language()->addToStack('email_test_subject'), \IPS\Member::loggedIn()->language()->addToStack('email_test_message'), \IPS\Member::loggedIn()->language()->addToStack('email_test_message') );
$email->from = \IPS\Settings::i()->email_out;
$result = $email->send( \IPS\Member::loggedIn()->email );
if ( $result === TRUE )
{
$messageHtml = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_okay_auto', 'success' );
}
elseif( $result instanceof \IPS\Email\Outgoing\Exception )
{
$messageHtml = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_error_auto', 'error', $result->getMessage() );
}
/* If php mail fails it throws a regular PHP error */
elseif( $result instanceof \ErrorException )
{
$messageHtml = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_error_auto', 'error', $result->getMessage() );
}
}
}
/* Build the test form */
$testFormHtml = '';
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'email_test' ) )
{
\IPS\Output::i()->sidebar['actions']['test'] = array(
'title' => 'email_test',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( '#testForm' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('email_test'), 'ipsDialog-content' => '#testForm' )
);
$testForm = new \IPS\Helpers\Form( 'test_form' );
$testForm->add( new \IPS\Helpers\Form\Email( 'from', \IPS\Settings::i()->email_out, TRUE ) );
$testForm->add( new \IPS\Helpers\Form\Email( 'to', \IPS\Member::loggedIn()->email, TRUE ) );
$testForm->add( new \IPS\Helpers\Form\Text( 'subject', \IPS\Member::loggedIn()->language()->addToStack('email_test_subject'), TRUE ) );
$testForm->add( new \IPS\Helpers\Form\TextArea( 'message', \IPS\Member::loggedIn()->language()->addToStack('email_test_message'), TRUE ) );
if ( $values = $testForm->values() )
{
$email = \IPS\Email::buildFromContent( $values['subject'], $values['message'], $values['message'] );
$email->from = $values['from'];
$result = $email->send( $values['to'] );
if ( $result === TRUE )
{
$messageHtml = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_okay', 'success' );
}
elseif( $result instanceof \IPS\Email\Outgoing\Exception )
{
$messageHtml = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_error', 'error', $result->getMessage() );
}
/* If php mail fails it throws a regular PHP error */
elseif( $result instanceof \ErrorException )
{
$messageHtml = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_error', 'error', $result->getMessage() );
}
}
$testFormHtml = \IPS\Theme::i()->getTemplate( 'global' )->block( 'email_test', $testForm, FALSE, 'ipsJS_hide', 'testForm' );
}
/* Add a button for logs */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'email_errorlog' ) )
{
\IPS\Output::i()->sidebar['actions']['errorLog'] = array(
'title' => 'emailerrorlogs',
'icon' => 'exclamation-triangle',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=email&do=errorLog' ),
);
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('email_settings');
\IPS\Output::i()->output = $messageHtml;
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'email_settings', $settingsForm );
\IPS\Output::i()->output .= $testFormHtml;
}
/**
* Error Log
*
* @return void
*/
protected function errorLog()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_errorlog' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_mail_error_logs', \IPS\Http\Url::internal( 'app=core&module=settings&controller=email&do=errorLog' ) );
$table->langPrefix = 'emailerrorlogs_';
/* Columns we need */
$table->include = array( 'mlog_to', 'mlog_subject', 'mlog_date', 'mlog_msg' );
$table->widths = array( 'mlog_date' => '15', 'mlog_to' => '20', 'mlog_subject' => '20', 'mlog_msg' => '35' );
$table->sortBy = $table->sortBy ?: 'mlog_date';
$table->sortDirection = $table->sortDirection ?: 'DESC';
$table->noSort = array( 'mlog_msg' );
/* Search */
$table->quickSearch = 'mlog_to';
$table->advancedSearch = array(
'mlog_to' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'mlog_from' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'mlog_subject' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'mlog_msg' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'mlog_content' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
);
/* Custom parsers */
$table->parsers = array(
'mlog_date' => function( $val, $row )
{
return \IPS\DateTime::ts( $val );
},
'mlog_msg' => function( $val, $row )
{
if( !$val )
{
$val = \IPS\Member::loggedIn()->language()->get('phpmail_not_sent');
}
return \IPS\Theme::i()->getTemplate( 'logs' )->emailErrorLog( nl2br( htmlspecialchars( $val, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ), $row );
},
'mlog_content' => function( $val, $row )
{
return \IPS\Theme::i()->getTemplate( 'logs' )->emailErrorBody( $val, $row );
},
);
/* Row buttons */
$table->rowButtons = function( $row )
{
$return = array();
$return['view'] = array(
'icon' => 'search',
'title' => 'view_email_error_body',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=email&do=errorLogView&id=' ) . $row['mlog_id'],
'hotkey' => 'Return',
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('emailerrorlogs_mlog_content') )
);
$return['resend'] = array(
'icon' => 'refresh',
'title' => 'resend_email_error',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=email&do=errorLogResend&id=' ) . $row['mlog_id'],
);
return $return;
};
/* Add a button for settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'email_errorlog_prune' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=email&do=errorLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('emailerrorlogs');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'title', (string) $table );
}
/**
* Attempt to resend the email that failed
*
* @return void
*/
public function errorLogResend()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_errorlog' );
$id = (int) \IPS\Request::i()->id;
$log = \IPS\Db::i()->select( '*', 'core_mail_error_logs', array( 'mlog_id=?', $id ) )->first();
$email = json_decode( $log['mlog_resend_data'], true );
try
{
$emailHandler = \IPS\Email::buildFromRaw( $email['headers'], $email['body'] );
$emailHandler->subject = $log['mlog_subject'];
$emailHandler->to = explode( ',', $log['mlog_to'] );
$emailHandler->from = $log['mlog_from'];
$emailHandler->forceSend( $email['boundary'] );
}
catch( \Exception $e )
{
\IPS\Output::i()->error( $e->getMessage(), '4C143/1', 500, '' );
}
\IPS\Db::i()->delete( 'core_mail_error_logs', array( 'mlog_id=?', $id ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=settings&controller=email&do=errorLog" ), 'emailerror_resent' );
}
/**
* View a failed email details
*
* @return void
*/
public function errorLogView()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_errorlog' );
$id = (int) \IPS\Request::i()->id;
$log = \IPS\Db::i()->select( '*', 'core_mail_error_logs', array( 'mlog_id=?', $id ) )->first();
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('logs')->emailErrorBody( $log );
}
/**
* Error log Prune Settings
*
* @return void
*/
protected function errorLogSettings()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_errorlog_prune' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Number( 'prune_log_email_error', \IPS\Settings::i()->prune_log_email_error, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days'), 'prune_log_email_error' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__emailerrorlog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=email&do=errorLog' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('emailerrorlogssettings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'emailerrorlogssettings', $form, FALSE );
}
}
@@ -0,0 +1,77 @@
<?php
/**
* @brief general
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* general
*/
class _general extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'general_manage' );
parent::execute();
}
/**
* Manage Settings
*
* @return void
*/
protected function manage()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'board_name', \IPS\Settings::i()->board_name, TRUE ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'site_online', \IPS\Settings::i()->site_online, FALSE, array(
'togglesOff' => array( 'site_offline_message_id' ),
) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'site_offline_message', \IPS\Settings::i()->site_offline_message, FALSE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'onlineoffline', 'attachIds' => array( NULL, NULL, 'site_offline_message' ) ), NULL, NULL, NULL, 'site_offline_message_id' ) );
$form->add( new \IPS\Helpers\Form\Address( 'site_address', \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address ), FALSE ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'copyright_line', NULL, FALSE, array( 'app' => 'core', 'key' => 'copyright_line_value', 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('copyright_line_placeholder') ) ) );
$form->addHeader( 'home_link' );
$form->add( new \IPS\Helpers\Form\YesNo( 'show_home_link', \IPS\Settings::i()->show_home_link, FALSE, array(
'togglesOn' => array( 'home_name', 'home_url' ),
) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'home_name', NULL, FALSE, array( 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('home_name_placeholder'), 'app' => 'core', 'key' => 'home_name_value' ), NULL, NULL, NULL, 'home_name' ) );
$form->add( new \IPS\Helpers\Form\Url( 'home_url', \IPS\Settings::i()->home_url, FALSE, array( 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('home_url_placeholder') ), NULL, NULL, NULL, 'home_url' ) );
if ( $values = $form->values() )
{
\IPS\Lang::saveCustom( 'core', "copyright_line_value", $values['copyright_line'] );
\IPS\Lang::saveCustom( 'core', "home_name_value", $values['home_name'] );
unset( $values['copyright_line'], $values['home_name'] );
$form->saveAsSettings();
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__general_settings' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_settings_general');
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'menu__core_settings_general', $form );
}
}
Whitespace-only changes.
@@ -0,0 +1,123 @@
<?php
/**
* @brief licensekey
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* licensekey
*/
class _licensekey extends \IPS\Dispatcher\Controller
{
/**
* @brief Data about the license key from the store
*/
protected $licenseData = array();
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'licensekey_manage' );
parent::execute();
}
/**
* License key overview screen
*
* @return void
*/
protected function manage()
{
/* Get license info. If license info is empty, refresh it. */
$licenseData = \IPS\IPS::licenseKey();
/* If no license key has been supplied yet just show the form */
if( !isset( $licenseData['key'] ) )
{
return $this->settings();
}
/* Output */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('license_settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'licensekey', 'core' )->overview( $licenseData );
\IPS\Output::i()->sidebar['actions'] = array(
'refresh' => array(
'icon' => 'refresh',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=licensekey&do=refresh' ),
'title' => 'license_refresh',
),
'remove' => array(
'icon' => 'pencil',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=licensekey&do=settings' ),
'title' => 'license_change',
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('license_change') )
),
);
}
/**
* Refresh the license key data stored locally
*
* @return void
*/
protected function refresh()
{
/* Fetch the license key data and update our local storage */
unset( \IPS\Data\Store::i()->license_data );
/* Return the overview screen afterwards */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=licensekey' ), 'license_key_refreshed' );
}
/**
* Manage Settings
*
* @return void
*/
protected function settings()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'ipb_reg_number', NULL, TRUE, array(), function( $val ){
\IPS\IPS::checkLicenseKey( $val, \IPS\Settings::i()->base_url );
} ) );
if ( $values = $form->values() )
{
$values['ipb_reg_number'] = trim( $values['ipb_reg_number'] );
if ( mb_substr( $values['ipb_reg_number'], -12 ) === '-TESTINSTALL' )
{
$values['ipb_reg_number'] = mb_substr( $values['ipb_reg_number'], 0, -12 );
}
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__license_settings' );
/* Refresh the locally stored license info */
unset( \IPS\Data\Store::i()->license_data );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=licensekey' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('license_settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'menu__core_settings_licensekey', $form );
}
}
@@ -0,0 +1,308 @@
<?php
/**
* @brief Login Handlers
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 15 Mar 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* Login Handlers
*/
class _login extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\Login\LoginAbstract';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'login_manage' );
return parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'login_settings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&do=settings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('login_settings') )
),
'forcelogout' => array(
'title' => 'force_all_logout',
'icon' => 'lock',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&do=forceLogout' ),
'data' => array( 'confirm' => '' ),
),
);
/* Show IPS Connect "master" information */
$masterUrl = \IPS\Http\Url::internal( 'applications/core/interface/ipsconnect/ipsconnect.php', 'none' );
$masterKey = md5( md5( \IPS\Settings::i()->sql_user . \IPS\Settings::i()->sql_pass ) . \IPS\Settings::i()->board_start );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'login_ipsconnect_info', FALSE, array( 'sprintf' => array( $masterUrl, $masterKey ) ) ), 'info', NULL, FALSE );
return parent::manage();
}
/**
* Force all users to be logged out
*
* @return void
*/
protected function forceLogout()
{
\IPS\Db::i()->update( 'core_members', array( 'member_login_key' => '' ) );
\IPS\Db::i()->delete( 'core_sessions' );
\IPS\Session::i()->log( 'acplogs__logout_force' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login' ), 'logged_out_force' );
}
/**
* Toggle Enabled/Disable
* Overridden so we can check the settings are okay before we enable
*
* @return void
*/
protected function enableToggle()
{
$node = \IPS\Login\LoginAbstract::load( \IPS\Request::i()->id );
if ( \IPS\Request::i()->status )
{
if ( method_exists( $node, 'testSettings' ) )
{
try
{
$node->testSettings();
}
catch ( \Exception $e )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=settings&controller=login&do=form&id={$node->key}" ) );
}
}
}
else
{
$others = \IPS\Db::i()->select( 'count(*)', 'core_login_handlers', array( 'login_enabled=? and login_key<>?', 1, $node->key ) )->first();
if( !$others )
{
\IPS\Output::i()->error( 'login_atleast_one', '1C166/3', 403, '' );
}
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
return parent::enableToggle();
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
$node = \IPS\Login\LoginAbstract::load( \IPS\Request::i()->id );
$others = \IPS\Db::i()->select( 'count(*)', 'core_login_handlers', array( 'login_enabled=? and login_key<>?', 1, $node->key ) )->first();
if( !$others )
{
\IPS\Output::i()->error( 'login_atleast_one', '1C166/3', 403, '' );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
return parent::delete();
}
/**
* Settings
*
* @return void
*/
protected function settings()
{
/* Build Form */
$form = new \IPS\Helpers\Form();
$form->addHeader( 'ipb_bruteforce_attempts' );
$form->add( new \IPS\Helpers\Form\Number( 'ipb_bruteforce_attempts', \IPS\Settings::i()->ipb_bruteforce_attempts, FALSE, array( 'min' => 0, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('failed_logins'), 'ipb_bruteforce_attempts' ) );
$form->add( new \IPS\Helpers\Form\Number( 'ipb_bruteforce_period', \IPS\Settings::i()->ipb_bruteforce_period, FALSE, array( 'min' => 0, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('minutes'), 'ipb_bruteforce_period' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'ipb_bruteforce_unlock', \IPS\Settings::i()->ipb_bruteforce_unlock, FALSE, array(), NULL, NULL, NULL, 'ipb_bruteforce_unlock' ) );
$form->addHeader( 'login_settings' );
/* Check if the site works over HTTPS before we allow them to change that */
$httpsValue = \IPS\Settings::i()->logins_over_https;
$httpsDisabled = FALSE;
$toggles = array();
if ( mb_substr( \IPS\Settings::i()->base_url, 0, 8 ) === 'https://' )
{
$httpsValue = TRUE;
$httpsDisabled = TRUE;
\IPS\Member::loggedIn()->language()->words['logins_over_https_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'logins_over_https_enabled', FALSE );
}
else
{
try
{
$response = \IPS\Http\Url::external( 'https://' . mb_substr( \IPS\Settings::i()->base_url, 7 ) )->request()->get();
}
catch ( \IPS\Http\Request\Exception $e )
{
$httpsValue = FALSE;
$httpsDisabled = TRUE;
$toggles[] = 'form_logins_over_https_warning';
\IPS\Member::loggedIn()->language()->words['logins_over_https_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'logins_over_https_disabled', FALSE, array( 'sprintf' => array( $e->getMessage() ) ) );
}
}
$form->add( new \IPS\Helpers\Form\YesNo( 'logins_over_https', $httpsValue, FALSE, array( 'disabled' => $httpsDisabled, 'togglesOn' => $toggles ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'disable_anonymous', !\IPS\Settings::i()->disable_anonymous, FALSE, array(), NULL, NULL, NULL, 'disable_anonymous' ) );
/* Save */
if ( $values = $form->values() )
{
$values['disable_anonymous'] = $values['disable_anonymous'] ? FALSE : TRUE;
$form->saveAsSettings( $values );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__login_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login' ), 'saved' );
}
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'login_settings', $form, FALSE );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'login_settings' );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'login_settings' ) );
}
/**
* Manually reprocess IPS Connect requests that are queued
*
* @return void
*/
protected function retryConnect()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('try_slave_request_again');
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal( "app=core&module=settings&controller=login&do=retryConnect&slave=" . \IPS\Request::i()->slave ),
function( $data )
{
/* On first cycle get data */
if ( !is_array( $data ) )
{
/* Get total number of failures to process for progress bar */
$data = array( 'done' => 0, 'total' => count( \IPS\Db::i()->select( 'id', 'core_ipsconnect_queue', array( 'slave_id=?', intval( \IPS\Request::i()->slave ) ) ) ) );
}
/* Get the next request */
try
{
$request = \IPS\Db::i()->select( 'q.*, s.*', array( 'core_ipsconnect_queue', 'q' ), array( 'q.slave_id=?', intval( \IPS\Request::i()->slave ) ), 'q.id asc', array( 0, 1 ) )
->join( array( 'core_ipsconnect_slaves', 's' ), "s.slave_id=q.slave_id" )
->first();
/* Try to process request again */
try
{
parse_str( $request['request_url'], $variables );
$response = \IPS\Http\Url::external( $request['slave_url'] )
->setQueryString( $variables )
->request()
->get();
if( $response->httpResponseCode !== NULL AND $response->httpResponseCode > 200 )
{
/* Update fail count */
\IPS\Db::i()->update( 'core_ipsconnect_queue', 'fail_count=fail_count+1', array( 'id=?', $request['id'] ) );
/* Show error message */
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'connect_failure_details', FALSE, array( 'sprintf' =>
array( \IPS\Member::loggedIn()->language()->addToStack('connect_slavefail_http', FALSE, array( 'sprintf' => array( $response->httpResponseCode ) ) ) )
) ), '4C166/1', 503, '' );
}
$response = $response->decodeJson();
/* If this is a registered slave but the slave is telling us Connect is disabled, remove it */
if( isset( $response['status'] ) AND $response['status'] == 'DISABLED' )
{
\IPS\Db::i()->delete( 'core_ipsconnect_slaves', array( 'slave_id=?', $request['slave_id'] ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Db::i()->select( 'COUNT(*)', 'core_ipsconnect_slaves' )->first() ), array( 'conf_key=?', 'connect_slaves' ) );
unset( \IPS\Data\Store::i()->settings );
}
else if( !isset( $response['status'] ) OR $response['status'] != 'SUCCESS' )
{
throw new \RuntimeException( $response['status'] );
}
/* If we are here, request succeeded - remove from queue */
\IPS\Db::i()->delete( 'core_ipsconnect_queue', array( 'id=?', $request['id'] ) );
}
catch( \RuntimeException $e )
{
/* Update fail count */
\IPS\Db::i()->update( 'core_ipsconnect_queue', 'fail_count=fail_count+1', array( 'id=?', $request['id'] ) );
/* The request failed - show the admin why */
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack('connect_failure_details', FALSE, array( 'sprintf' => array( $e->getMessage() ) ) ), '4C166/2', 503, '' );
}
$data['done']++;
/* Return null to indicate we are done */
return array( $data, 'connect_retry_success', round( $data['done'] / $data['total'] ) );
}
catch( \UnderflowException $e )
{
\IPS\Session::i()->log( 'acplog__connect_queue_cleared' );
/* Disable task */
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='ipsconnect'" );
return NULL;
}
},
function()
{
/* And redirect back to the dashboard */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=overview&controller=dashboard' ), 'connect_queue_cleared' );
}
);
}
}
@@ -0,0 +1,780 @@
<?php
/**
* @brief Manage Posting Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 20 Jun 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* Manage Posting Settings
*/
class _posting extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
/* Build tab list */
$this->tabs = array();
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'posting_manage' ) )
{
$this->tabs['general'] = 'posting_general';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'posting_manage_acronym' ) )
{
$this->tabs['acronymExpansion'] = 'acronym_expansion';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'posting_manage_polls' ) )
{
$this->tabs['polls'] = 'polls';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'posting_manage_profanity' ) )
{
$this->tabs['profanityFilters'] = 'profanity';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'posting_manage_tags' ) )
{
$this->tabs['tags'] = 'tags';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'posting_manage_url' ) )
{
$this->tabs['urlFilters'] = 'url_settings';
}
/* Choose active tab */
if ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $this->tabs ) )
{
$this->activeTab = \IPS\Request::i()->tab;
}
else
{
$keys = array_keys( $this->tabs );
$this->activeTab = array_shift( $keys );
}
/* Run */
parent::execute();
}
/**
* Manage Posting Settings
*
* @return void
*/
protected function manage()
{
/* Work out output */
$activeTabContents = call_user_func( array( $this, '_manage'.ucfirst( $this->activeTab ) ) );
/* If this is an AJAX request, just return it */
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $activeTabContents;
return;
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_settings_posting');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->tabs( $this->tabs, $this->activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=core&module=settings&controller=posting" ) );
}
/**
* Manage general posting settings
*
* @return string HTML to display
*/
protected function _manageGeneral()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage' );
/* Build Form */
$form = new \IPS\Helpers\Form;
$form->addHeader('posting_attachments');
$form->add( new \IPS\Helpers\Form\Radio( 'attach_allowed_types', \IPS\Settings::i()->attach_allowed_types, FALSE, array(
'options' => array( 'all' => 'attach_allowed_types_all', 'images' => 'attach_allowed_types_images', 'none' => 'attach_allowed_types_none' ),
'toggles' => array( 'all' => array( 'attach_allowed_extensions', 'attachment_resample_size', 'attachment_image_size' ), 'images' => array( 'attachment_resample_size', 'attachment_image_size' ) )
) ) );
$form->add( new \IPS\Helpers\Form\Text( 'attach_allowed_extensions', \IPS\Settings::i()->attach_allowed_extensions ? explode( ',', \IPS\Settings::i()->attach_allowed_extensions ) : NULL, FALSE, array( 'nullLang' => 'no_restriction', 'autocomplete' => array( 'freeChoice' => TRUE, 'source' => array( 'doc', 'docx', 'log', 'msg', 'odt', 'pages', 'rtf', 'tex', 'txt', 'wpd', 'wps', 'csv', 'dat', 'gbr', 'ged', 'key', 'keychain', 'pps', 'ppt', 'pptx', 'sdf', 'tar', 'tax2012', 'tax2014', 'vcf', 'xml', 'aif', 'iff', 'm3u', 'm4a', 'mid', 'mp3', 'mpa', 'ra', 'wav', 'wma', '3g2', '3gp', 'asf', 'asx', 'avi', 'flv', 'm4v', 'mov', 'mp4', 'mpg', 'rm', 'srt', 'swf', 'vob', 'wmv', '3dm', '3ds', 'max', 'obj', 'bmp', 'dds', 'gif', 'jpg', 'png', 'psd', 'pspimage', 'tga', 'thm', 'tif', 'tiff', 'yuv', 'ai', 'eps', 'ps', 'svg', 'indd', 'pct', 'pdf', 'xlr', 'xls', 'xlsx', 'accdb', 'db', 'dbf', 'mdb', 'pdb', 'sql', 'apk', 'app', 'bat', 'cgi', 'com', 'exe', 'gadget', 'jar', 'pif', 'vb', 'wsf', 'dem', 'gam', 'nes', 'rom', 'sav', 'dwg', 'dxf', 'gpx', 'kml', 'kmz', 'asp', 'aspx', 'cer', 'cfm', 'csr', 'css', 'htm', 'html', 'js', 'jsp', 'php', 'rss', 'xhtml', 'crx', 'plugin', 'fnt', 'fon', 'otf', 'ttf', 'cab', 'cpl', 'cur', 'deskthemepack', 'dll', 'dmp', 'drv', 'icns', 'ico', 'lnk', 'sys', 'cfg', 'ini', 'prf', 'hqx', 'mim', 'uue', '7z', 'cbr', 'deb', 'gz', 'pkg', 'rar', 'rpm', 'sitx', 'tar.gz', 'zip', 'zipx', 'bin', 'cue', 'dmg', 'iso', 'mdf', 'toast', 'vcd', 'c', 'class', 'cpp', 'cs', 'dtd', 'fla', 'h', 'java', 'lua', 'm', 'pl', 'py', 'sh', 'sln', 'swift', 'vcxproj', 'xcodeproj', 'bak', 'tmp', 'crdownload', 'ics', 'msi', 'part', 'torrent' ) ) ), NULL, NULL, NULL, 'attach_allowed_extensions' ) );
$form->addHeader('posting_images');
$form->add( new \IPS\Helpers\Form\WidthHeight( 'attachment_resample_size', \IPS\Settings::i()->attachment_resample_size ? explode( 'x', \IPS\Settings::i()->attachment_resample_size ) : array( 0, 0 ), FALSE, array( 'resizableDiv' => FALSE, 'unlimited' => array( 0, 0 ) ), NULL, NULL, NULL, 'attachment_resample_size' ) );
$current = ( isset( \IPS\Settings::i()->attachment_image_size ) ) ? explode( 'x', \IPS\Settings::i()->attachment_image_size ) : array( 1000, 750 );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'attachment_image_size', $current, FALSE, array( 'resizableDiv' => FALSE ), NULL, NULL, NULL, 'attachment_image_size' ) );
$form->add( new \IPS\Helpers\Form\Number( 'max_video_width', \IPS\Settings::i()->max_video_width, FALSE, array( 'unlimited' => 0 ), NULL, NULL, 'px' ) );
$form->addHeader('posting_content');
$form->add( new \IPS\Helpers\Form\YesNo( 'strip_quotes', !\IPS\Settings::i()->strip_quotes, FALSE, array(), NULL, NULL, NULL, 'strip_quotes' ) );
$form->add( new \IPS\Helpers\Form\Number( 'max_title_length', \IPS\Settings::i()->max_title_length, FALSE, array( 'max' => 255 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('max_title_length_suffix') ) );
$form->add( new \IPS\Helpers\Form\Number( 'merge_concurrent_posts', \IPS\Settings::i()->merge_concurrent_posts, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('minutes') ) );
$form->add( new \IPS\Helpers\Form\Number( 'flood_control', \IPS\Settings::i()->flood_control, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'none' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('seconds') ) );
$form->addHeader('edit_log');
$form->add( new \IPS\Helpers\Form\Radio( 'edit_log', \IPS\Settings::i()->edit_log, FALSE, array(
'options' => array(
0 => 'edit_log_none',
1 => 'edit_log_simple',
2 => 'edit_log_full'
),
'toggles' => array(
2 => array( 'edit_log_public', 'edit_log_prune' )
)
) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'edit_log_public', \IPS\Settings::i()->edit_log_public, FALSE, array(), NULL, NULL, NULL, 'edit_log_public' ) );
$form->add( new \IPS\Helpers\Form\Number( 'edit_log_prune', \IPS\Settings::i()->edit_log_prune, FALSE, array( 'unlimited' => -1, 'unlimitedLang' => 'never' ), function( $value ){ if( $value < 1 AND $value != -1 ) { throw new \InvalidArgumentException('form_required'); } }, NULL, \IPS\Member::loggedIn()->language()->addToStack('days'), 'edit_log_prune' ) );
$form->addHeader('posting_items');
$form->add( new \IPS\Helpers\Form\Number( 'topic_redirect_prune', \IPS\Settings::i()->topic_redirect_prune, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days') ) );
$hasReviewableApps = false;
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter', NULL, NULL, NULL, TRUE ) as $router )
{
foreach ( $router->classes as $class )
{
$classes[] = $class;
if ( isset( $class::$commentClass ) )
{
$hasReviewableApps = true;
break 2;
}
}
}
if ( $hasReviewableApps )
{
$form->add( new \IPS\Helpers\Form\Radio( 'reviews_rating_out_of', \IPS\Settings::i()->reviews_rating_out_of, FALSE, array(
'options' => array(
5 => 'reviews_rating_out_of_5',
10 => 'reviews_rating_out_of_10'
)
) ) );
}
/* Save values */
if ( $values = $form->values() )
{
$clearCss = ( $values['max_video_width'] !== \IPS\Settings::i()->max_video_width );
$values['strip_quotes'] = $values['strip_quotes'] ? FALSE : TRUE;
$values['attachment_resample_size'] = implode( 'x', $values['attachment_resample_size'] );
$values['attachment_image_size'] = implode( 'x', $values['attachment_image_size'] );
$values['attach_allowed_extensions'] = is_array( $values['attach_allowed_extensions'] ) ? implode( ',', array_unique( array_map( function( $val )
{
return ltrim( $val, '.' );
}, $values['attach_allowed_extensions'] ) ) ) : '';
$values['max_video_width_css'] = ( $values['max_video_width'] ) ? $values['max_video_width'] . 'px' : 'none';
$form->saveAsSettings( $values );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__posting_general_settings' );
if ( $clearCss )
{
\IPS\Theme::deleteCompiledCss();
/* redirect so CSS can rebuild */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=general' ), 'saved' );
}
}
return $form;
}
/**
* Show profanity filters
*
* @return string HTML to display
*/
protected function _manageProfanityFilters()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_profanity' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_profanity_filters', \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=profanityFilters' ) );
$table->langPrefix = 'profanity_';
$table->mainColumn = 'type';
/* Columns we need */
$table->include = array( 'type', 'swop', 'm_exact' );
/* Default sort options */
$table->sortBy = $table->sortBy ?: 'type';
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Filters */
$table->filters = array(
'profanity_filter_exact' => 'm_exact=1',
'profanity_filter_loose' => 'm_exact=0',
);
/* Search */
$table->quickSearch = 'type';
/* Custom parsers */
$table->parsers = array(
'm_exact' => function( $val, $row )
{
return ( $val ) ? \IPS\Member::loggedIn()->language()->addToStack('profanity_filter_exact') : \IPS\Member::loggedIn()->language()->addToStack('profanity_filter_loose');
}
);
/* Specify the root buttons */
$table->rootButtons['add'] = array(
'icon' => 'plus',
'title' => 'profanity_add',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=profanity' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('profanity_add') )
);
$table->rootButtons['download'] = array(
'icon' => 'download',
'title' => 'download',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=downloadProfanity' ),
'data' => array( 'confirm' => '', 'confirmMessage' => \IPS\Member::loggedIn()->language()->addToStack('profanity_download'), 'confirmIcon' => 'info', 'confirmButtons' => json_encode( array( 'ok' => \IPS\Member::loggedIn()->language()->addToStack('download'), 'cancel' => \IPS\Member::loggedIn()->language()->addToStack('cancel') ) ) )
);
/* And the row buttons */
$table->rowButtons = function( $row )
{
$return = array();
$return['edit'] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=profanity&id=' ) . $row['wid'],
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit') )
);
$return['delete'] = array(
'icon' => 'times',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=deleteProfanityFilters&id=' ) . $row['wid'],
'data' => array( 'delete' => '' ),
);
return $return;
};
/* So people don't set up filters, test with their admin account and think it's not working */
$groupsThatBypass = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups', array( 'g_bypass_badwords=1' ) ), 'IPS\Member\Group' );
if ( count( $groupsThatBypass ) )
{
$names = array();
foreach ( $groupsThatBypass as $group )
{
$names[] = $group->name;
}
$message = \IPS\Theme::i()->getTemplate( 'forms' )->blurb( \IPS\Member::loggedIn()->language()->addToStack( 'profanity_bypass_groups', FALSE, array( 'htmlsprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $names ) ) ) ), FALSE, TRUE );
}
else
{
$message = \IPS\Theme::i()->getTemplate( 'forms' )->blurb( 'profanity_no_bypass_groups', TRUE, TRUE );
}
/* Display */
return $message . $table;
}
/**
* Show url filters
*
* @return string HTML to display
*/
protected function _manageUrlFilters()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_url' );
/* Build Form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'ipb_url_filter_option', \IPS\Settings::i()->ipb_url_filter_option, FALSE, array(
'options' => array(
'none' => 'url_none',
'black' => 'url_blacklist',
'white' => "url_whitelist" ),
'toggles' => array(
'black' => array( 'ipb_url_blacklist' ),
'white' => array( 'ipb_url_whitelist' ),
'none' => array(),
)
) ) );
$form->add( new \IPS\Helpers\Form\Stack( 'ipb_url_whitelist', \IPS\Settings::i()->ipb_url_whitelist ? explode( ",", \IPS\Settings::i()->ipb_url_whitelist ) : array(), FALSE, array(), NULL, NULL, NULL, 'ipb_url_whitelist' ) );
$form->add( new \IPS\Helpers\Form\Stack( 'ipb_url_blacklist', \IPS\Settings::i()->ipb_url_blacklist ? explode( ",", \IPS\Settings::i()->ipb_url_blacklist ) : array(), FALSE, array(), NULL, NULL, NULL, 'ipb_url_blacklist' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'links_external', \IPS\Settings::i()->links_external ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'posts_add_nofollow', \IPS\Settings::i()->posts_add_nofollow, FALSE, array( 'togglesOn' => array( 'posts_add_nofollow_exclude' ) ), NULL, NULL, NULL, 'posts_add_nofollow' ) );
$form->add( new \IPS\Helpers\Form\Stack( 'posts_add_nofollow_exclude', \IPS\Settings::i()->posts_add_nofollow_exclude ? json_decode( \IPS\Settings::i()->posts_add_nofollow_exclude ) : array(), FALSE, array( 'placeholder' => 'example.com' ), NULL, NULL, NULL, 'posts_add_nofollow_exclude' ) );
/* Save values */
if ( $values = $form->values() )
{
$values['ipb_url_whitelist'] = implode( ",", $values['ipb_url_whitelist'] );
$values['ipb_url_blacklist'] = implode( ",", $values['ipb_url_blacklist'] );
/* We need to clean these up */
$nofollowExclude = array();
foreach( $values['posts_add_nofollow_exclude'] as $domain )
{
/* We only want to compare against the domain, not the full URL */
$domain = str_replace( array( 'http://', 'https://' ), '', $domain );
/* And we are comparing against the non-www. version during parsing */
$domain = preg_replace( '/^www\./', '', $domain );
/* Use the domain as the key as well to prevent duplicates for efficiency purposes */
$nofollowExclude[ $domain ] = $domain;
}
$values['posts_add_nofollow_exclude'] = json_encode( array_values( $nofollowExclude ) );
$form->saveAsSettings( $values );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__url_filter_settings' );
/* Redirect otherwise our changes to posts_add_nofollow_exclude won't reflect initially */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=urlFilters' ), 'saved' );
}
return $form;
}
/**
* Acronym expansion
*
* @return string HTML to display
*/
protected function _manageAcronymExpansion()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_acronym' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_acronyms', \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=acronymExpansion' ) );
$table->langPrefix = 'acronym_';
$table->mainColumn = 'a_short';
/* Columns we need */
$table->include = array( 'a_short', 'a_long', 'a_casesensitive' );
/* Default sort options */
$table->sortBy = $table->sortBy ?: 'a_short';
$table->sortDirection = $table->sortDirection ?: 'asc';
/* Search */
$table->quickSearch = 'a_short';
/* Custom parsers */
$table->parsers = array(
'a_casesensitive'=> function( $val, $row )
{
return ( $val ) ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
},
);
/* Specify the buttons */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'acronym', 'acronym_add' ) )
{
$table->rootButtons = array(
'add' => array(
'icon' => 'plus',
'title' => 'acronym_add',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=acronym' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('acronym_add') )
)
);
}
$table->rowButtons = function( $row )
{
$return = array();
$return['edit'] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=acronym&id=' ) . $row['a_id'],
);
$return['delete'] = array(
'icon' => 'times',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=deleteAcronym&id=' ) . $row['a_id'],
'data' => array( 'delete' => '' ),
);
return $return;
};
return $table;
}
/**
* Manage poll settings
*
* @return string HTML to display
*/
protected function _managePolls()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_polls' );
$form = new \IPS\Helpers\Form();
$form->addHeader('poll_creation');
$form->add( new \IPS\Helpers\Form\Number( 'max_poll_questions', \IPS\Settings::i()->max_poll_questions ) );
$form->add( new \IPS\Helpers\Form\Number( 'max_poll_choices', \IPS\Settings::i()->max_poll_choices ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'poll_allow_public', \IPS\Settings::i()->poll_allow_public ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'ipb_poll_only', \IPS\Settings::i()->ipb_poll_only ) );
$form->add( new \IPS\Helpers\Form\Number( 'startpoll_cutoff', \IPS\Settings::i()->startpoll_cutoff, FALSE, array( 'unlimited' => -1, 'unlimitedLang' => 'always' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('hours') ) );
$form->addHeader('poll_voting');
$form->add( new \IPS\Helpers\Form\YesNo( 'allow_creator_vote', \IPS\Settings::i()->allow_creator_vote ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'poll_allow_vdelete', \IPS\Settings::i()->poll_allow_vdelete, FALSE ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'allow_result_view', \IPS\Settings::i()->allow_result_view, FALSE, array(), NULL, NULL, NULL, 'allow_result_view' ) );
if ( $form->saveAsSettings() )
{
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__poll_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=polls' ), 'saved' );
}
return \IPS\Theme::i()->getTemplate( 'forms' )->blurb( 'polls_blurb' ) . $form;
}
/**
* Manage tag settings
*
* @return string HTML to display
*/
protected function _manageTags()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_tags' );
$form = new \IPS\Helpers\Form();
$form->add( new \IPS\Helpers\Form\YesNo( 'tags_enabled', \IPS\Settings::i()->tags_enabled, FALSE, array( 'togglesOn' => array( 'tags_can_prefix', 'tags_open_system', 'tags_predefined', 'tags_force_lower', 'tags_min', 'tags_max', 'tags_len_min', 'tags_len_max', 'tags_clean' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'tags_can_prefix', \IPS\Settings::i()->tags_can_prefix, FALSE, array(), NULL, NULL, NULL, 'tags_can_prefix' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'tags_open_system', \IPS\Settings::i()->tags_open_system, FALSE, array( 'options' => array( 1 => 'tags_open_system_open', 0 => 'tags_open_system_closed' ) ), NULL, NULL, NULL, 'tags_open_system' ) );
$form->add( new \IPS\Helpers\Form\Text( 'tags_predefined', \IPS\Settings::i()->tags_predefined, FALSE, array( 'autocomplete' => array( 'unique' => TRUE ) ), NULL, NULL, NULL, 'tags_predefined' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'tags_force_lower', \IPS\Settings::i()->tags_force_lower, FALSE, array(), NULL, NULL, NULL, 'tags_force_lower' ) );
$form->add( new \IPS\Helpers\Form\Number( 'tags_min', \IPS\Settings::i()->tags_min, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'tags_min_none', 'unlimitedToggles' => array( 'tags_min_req' ), 'unlimitedToggleOn' => FALSE ), NULL, NULL, NULL, 'tags_min' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'tags_min_req', \IPS\Settings::i()->tags_min_req, FALSE, array(), NULL, NULL, NULL, 'tags_min_req' ) );
$form->add( new \IPS\Helpers\Form\Number( 'tags_max', \IPS\Settings::i()->tags_max, FALSE, array( 'unlimited' => 0 ), NULL, NULL, NULL, 'tags_max' ) );
$form->add( new \IPS\Helpers\Form\Number( 'tags_len_min', \IPS\Settings::i()->tags_len_min, FALSE, array( 'unlimited' => 0 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack( 'characters' ), 'tags_len_min' ) );
$form->add( new \IPS\Helpers\Form\Number( 'tags_len_max', \IPS\Settings::i()->tags_len_max, FALSE, array( 'unlimited' => 0 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack( 'characters' ), 'tags_len_max' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'tags_clean', \IPS\Settings::i()->tags_clean, FALSE, array(), NULL, NULL, NULL, 'tags_clean' ) );
if ( ! \IPS\Settings::i()->tags_open_system and ! \IPS\Settings::i()->tags_predefined )
{
\IPS\Member::loggedIn()->language()->words['tags_predefined_warning'] = \IPS\Member::loggedIn()->language()->words['tags_predefined__warning'];
}
if ( $form->saveAsSettings() )
{
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__tag_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=tags' ), 'saved' );
}
return $form;
}
/**
* Add/Edit Profanity Filter
*
* @return void
*/
public function profanity()
{
/* Permission check */
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_profanity' );
/* Init */
$current = NULL;
if ( \IPS\Request::i()->id )
{
try
{
$current = \IPS\Db::i()->select( '*', 'core_profanity_filters', array( 'wid=?', \IPS\Request::i()->id ) )->first();
}
catch ( \UnderflowException $e ) { }
}
/* Build form */
$form = new \IPS\Helpers\Form();
if ( !$current )
{
$form->addTab('add');
}
$form->add( new \IPS\Helpers\Form\Text( 'profanity_type', ( $current ) ? $current['type'] : NULL, NULL, array() ) );
$form->add( new \IPS\Helpers\Form\Text( 'profanity_swop', ( $current ) ? $current['swop'] : NULL, NULL, array() ) );
$form->add( new \IPS\Helpers\Form\Radio( 'profanity_m_exact', ( $current ) ? $current['m_exact'] : NULL, FALSE, array(
'options' => array(
'1' => 'profanity_filter_exact',
'0' => 'profanity_filter_loose' ) )
) );
if ( !$current )
{
$form->addTab('upload');
$form->add( new \IPS\Helpers\Form\Upload( 'profanity_upload', NULL, NULL, array( 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ) ) );
}
/* Handle submissions */
if ( $values = $form->values() )
{
/* Upload */
if ( isset( $values['profanity_upload'] ) and $values['profanity_upload'] )
{
/* Move it to a temporary location */
$tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
move_uploaded_file( $values['profanity_upload'], $tempFile );
/* Initate a redirector */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=importProfanity&file=' . urlencode( $tempFile ) . '&key=' . md5_file( $tempFile ) ) );
}
/* Normal */
else
{
if ( $values['profanity_type'] and $values['profanity_swop'] )
{
$save = array(
'type' => $values['profanity_type'],
'swop' => $values['profanity_swop'],
'm_exact' => $values['profanity_m_exact']
);
if( $current )
{
\IPS\Db::i()->update( 'core_profanity_filters', $save, array( 'wid=?', $current['wid'] ) );
}
else
{
\IPS\Db::i()->insert( 'core_profanity_filters', $save );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=profanityFilters' ), 'saved' );
}
else
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('profanity_add_error');
}
}
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('profanity');
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Output::i()->title );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( \IPS\Output::i()->title, $form, FALSE );
}
/**
* Download Profanity Filters
*
* @return void
*/
public function downloadProfanity()
{
/* Permission Check */
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_profanity' );
$xml = new \XMLWriter;
$xml->openMemory();
$xml->setIndent( TRUE );
$xml->startDocument( '1.0', 'UTF-8' );
$xml->startElement('badwordexport');
$xml->startElement('badwordgroup');
foreach ( \IPS\Db::i()->select( '*', 'core_profanity_filters' ) as $profanity )
{
$xml->startElement('badword');
$xml->startElement('type');
$xml->text( $profanity['type'] );
$xml->endElement();
$xml->startElement('swop');
$xml->text( $profanity['swop'] );
$xml->endElement();
$xml->startElement('m_exact');
$xml->text( $profanity['m_exact'] );
$xml->endElement();
$xml->endElement();
}
$xml->endElement();
$xml->endElement();
$xml->endDocument();
\IPS\Output::i()->sendOutput( $xml->outputMemory(), 200, 'application/xml', array( 'Content-Disposition' => \IPS\Output::getContentDisposition( 'attachment', sprintf( \IPS\Member::loggedIn()->language()->get('profanity_download_name'), \IPS\Settings::i()->board_name ) . '.xml' ) ) );
}
/**
* Import from upload
*
* @return void
*/
protected function importProfanity()
{
if ( !file_exists( \IPS\Request::i()->file ) or md5_file( \IPS\Request::i()->file ) !== \IPS\Request::i()->key )
{
\IPS\Output::i()->error( 'generic_error', '3C256/1', 500, '' );
}
$url = \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&do=importProfanity&file=' . urlencode( \IPS\Request::i()->file ) . '&key=' . \IPS\Request::i()->key );
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
$url,
function( $data )
{
/* Open XML file */
$xml = new \XMLReader;
$xml->open( \IPS\Request::i()->file );
$xml->read(); //badwordexport
$xml->read(); //badwordexport
$xml->read(); //badwordgroup
$xml->read(); //badwordgroup
$xml->read();
/* Skip */
for ( $i = 0; $i < $data; $i++ )
{
$xml->next();
if ( !$xml->read() or $xml->name != 'badword' )
{
return NULL;
}
}
/* Import */
$save = array();
$xml->read();
$xml->read();
$save['type'] = $xml->readString();
$xml->next();
$xml->read();
$save['swop'] = $xml->readString();
$xml->next();
$xml->read();
$save['m_exact'] = $xml->readString();
try
{
$current = \IPS\Db::i()->select( 'wid', 'core_profanity_filters', array( 'type=?', $save['type'] ) )->first();
\IPS\Db::i()->update( 'core_profanity_filters', $save, array( 'wid=?', $current ) );
}
catch ( \UnderflowException $e )
{
\IPS\Db::i()->insert( 'core_profanity_filters', $save );
}
/* Move to next */
return array( ++$data, \IPS\Member::loggedIn()->language()->get('processing') );
},
function()
{
unset( \IPS\Data\Store::i()->languages );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=profanityFilters' ) );
}
);
}
/**
* Add/Edit Acronym
*
* @return void
*/
public function acronym()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_acronym' );
$current = NULL;
if ( \IPS\Request::i()->id )
{
$current = \IPS\core\Acronym::load( \IPS\Request::i()->id );
}
/* Build form */
$form = \IPS\core\Acronym::form( $current );
if ( $values = $form->values() )
{
\IPS\core\Acronym::createFromForm( $values, $current );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=posting&tab=acronymExpansion' ), 'saved' );
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acronym_a_short');
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Output::i()->title );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( \IPS\Output::i()->title, $form, FALSE );
}
/**
* Delete Profanity Filter
*
* @return void
*/
public function deleteProfanityFilters()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_profanity' );
\IPS\Db::i()->delete( 'core_profanity_filters', array( 'wid=?', \IPS\Request::i()->id ) );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* And redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=settings&controller=posting&tab=profanityFilters" ) );
}
/**
* Delete Acronym
*
* @return void
*/
public function deleteAcronym()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'posting_manage_acronym' );
\IPS\core\Acronym::load( \IPS\Request::i()->id )->delete();
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* And redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=settings&controller=posting&tab=acronymExpansion" ) );
}
}
@@ -0,0 +1,242 @@
<?php
/**
* @brief Search settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 14 Apr 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* Search settings
*/
class _search extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'search_manage' );
parent::execute();
}
/**
* Manage Settings
*
* @return void
* @note There is a hardcoded check for Sphinx here
* @todo The lang string replacements need to be checked <- checked for what?
*/
protected function manage()
{
/* Rebuild button */
\IPS\Output::i()->sidebar['actions'] = array(
'rebuildIndex' => array(
'title' => 'search_rebuild_index',
'icon' => 'undo',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=search&do=queueIndexRebuild' ),
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->get('search_rebuild_index_confirm') ),
),
);
\IPS\Member::loggedIn()->language()->words['search_engine__sphinx_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get('search_engine__sphinx_desc'), \IPS\Settings::i()->sphinx_base_path . '/sphinx.conf' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'search_engine', isset( \IPS\Request::i()->search_sphinx_server ) ? 'sphinx' : \IPS\Settings::i()->search_engine, TRUE, array( 'options' => $this->_getEngines(), 'toggles' => array( 'mysql' => array( 'search_index_timeframe' ), 'sphinx' => array( 'form_header_sphinx_header', 'form_header_sphinx_instructions', 'search_sphinx_server', 'search_sphinx_port', 'sphinx_base_path', 'sphinx_prefix' ) ) ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'search_index_timeframe', \IPS\Settings::i()->search_index_timeframe, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'all' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('search_index_timeframe_prefix'), \IPS\Member::loggedIn()->language()->addToStack('search_index_timeframe_suffix'), 'search_index_timeframe' ) );
$form->addHeader( 'sphinx_header' );
if ( \IPS\Settings::i()->search_engine == 'sphinx' )
{
$form->addMessage( 'sphinx_instructions', '', TRUE, 'form_header_sphinx_instructions' );
}
$form->add( new \IPS\Helpers\Form\Text( 'search_sphinx_server', \IPS\Settings::i()->search_sphinx_server, FALSE, array(), function( $val )
{
if ( $val === 'localhost' )
{
throw new \DomainException('search_sphinx_server_err');
}
}, NULL, NULL, 'search_sphinx_server' ) );
$form->add( new \IPS\Helpers\Form\Number( 'search_sphinx_port', \IPS\Settings::i()->search_sphinx_port, FALSE, array( 'placeholder' => "3312" ), NULL, NULL, NULL, 'search_sphinx_port' ) );
$form->add( new \IPS\Helpers\Form\Text( 'sphinx_base_path', \IPS\Settings::i()->sphinx_base_path, FALSE, array( 'placeholder' => "/var/sphinx" ), NULL, NULL, NULL, 'sphinx_base_path' ) );
$form->add( new \IPS\Helpers\Form\Text( 'sphinx_prefix', \IPS\Settings::i()->sphinx_prefix, FALSE, array(), NULL, NULL, NULL, 'sphinx_prefix' ) );
if ( $values = $form->values() )
{
$existing = \IPS\Settings::i()->search_engine;
$indexPrune = \IPS\Settings::i()->search_index_timeframe;
/* Did we just enable Sphinx? If so, we need some more instructions... */
if( $existing != $values['search_engine'] and $values['search_engine'] === 'sphinx' )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=search&do=sphinxInstructions' )->setQueryString( $values ) );
}
/* Otherwise go ahead and save... */
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__search_settings' );
/* And re-index if setting updated */
if( $existing != $values['search_engine'] or $indexPrune != $values['search_index_timeframe'] )
{
\IPS\Content\Search\Index::i()->rebuild();
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_settings_search');
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'menu__core_settings_search', $form );
}
/**
* Show Sphinx instructions
*
* @return void
*/
public function sphinxInstructions()
{
$configuration = array();
foreach ( array( 'search_sphinx_server', 'search_sphinx_port', 'sphinx_prefix', 'sphinx_base_path' ) as $k )
{
$configuration[ $k ] = isset( \IPS\Request::i()->$k ) ? \IPS\Request::i()->$k : '';
}
$error = NULL;
if ( isset( \IPS\Request::i()->check ) )
{
try
{
$database = \IPS\Db::i( 'SPHINXQL', array(
'sql_host' => \IPS\Request::i()->search_sphinx_server,
'sql_user' => NULL,
'sql_pass' => NULL,
'sql_database' => NULL,
'sql_port' => (int) \IPS\Request::i()->search_sphinx_port,
'sql_socket' => NULL,
'sql_utf8mb4' => NULL,
) );
$result = $database->query("SHOW STATUS");
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => 'sphinx' ), array( 'conf_key=?', 'search_engine' ) );
foreach ( $configuration as $k => $v )
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $v ), array( 'conf_key=?', $k ) );
\IPS\Settings::i()->$k = $v;
}
unset( \IPS\Data\Store::i()->settings );
\IPS\Session::i()->log( 'acplogs__search_settings' );
\IPS\Content\Search\Index::i()->rebuild();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=search' ), 'sphinx_setup_successful' );
}
catch( \Exception $exception )
{
\IPS\Log::i( \LOG_INFO )->write( get_class( $exception ) . "\n" . $exception->getCode() . ": " . $exception->getMessage() . "\n" . $exception->getTraceAsString() );
$error = 'sphinx_appear_invalid';
}
}
$configurationUrl = \IPS\Http\Url::internal( 'app=core&module=settings&controller=search&do=sphinxConfiguration' )->setQueryString( $configuration );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('sphinx_header');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'settings' )->sphinxInstructions( $configurationUrl, $error );
}
/**
* Get Sphinx conifguration file
*
* @return void
*/
public function sphinxConfiguration()
{
$server = isset( \IPS\Request::i()->search_sphinx_server ) ? \IPS\Request::i()->search_sphinx_server : \IPS\Settings::i()->search_sphinx_server;
$port = isset( \IPS\Request::i()->search_sphinx_port ) ? \IPS\Request::i()->search_sphinx_port : \IPS\Settings::i()->search_sphinx_port;
$prefix = isset( \IPS\Request::i()->sphinx_prefix ) ? \IPS\Request::i()->sphinx_prefix : \IPS\Settings::i()->sphinx_prefix;
$path = isset( \IPS\Request::i()->sphinx_base_path ) ? \IPS\Request::i()->sphinx_base_path : \IPS\Settings::i()->sphinx_base_path;
$collation = 'utf8_general_ci';
$sphinxConfiguration = <<<SPHINX
searchd
{
listen = {$server}:{$port}:mysql41
max_children = 30
pid_file = {$path}/buildsearchd.pid
preopen_indexes = 0
collation_server = {$collation}
workers = threads
}
index {$prefix}ips
{
type = rt
path = {$path}/index
rt_field = index_title
rt_field = index_content
rt_field = index_tags
rt_attr_bigint = index_object_id
rt_attr_bigint = index_item_id
rt_attr_bigint = index_container_id
rt_attr_bigint = index_author
rt_attr_bigint = index_views
rt_attr_bigint = index_num_comments
rt_attr_bigint = index_num_reviews
rt_attr_json = index_permissions
rt_attr_timestamp = index_date_created
rt_attr_timestamp = index_date_updated
rt_attr_string = index_class
rt_attr_uint = index_class_id
rt_attr_uint = index_hidden
}
SPHINX;
\IPS\Output::i()->sendOutput( $sphinxConfiguration, 200, 'application/octet-stream', array( 'Content-Disposition' => 'attachment; filename=sphinx.conf' ) );
}
/**
* Get the array of engine options
*
* @return array
*/
protected function _getEngines()
{
$engines = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . "/system/Content/Search/" ) as $file )
{
if ( $file->isDir() and !$file->isDot() and $file != 'index.html' )
{
$name = mb_strtolower( $file );
$engines[ $name ] = 'search_engine__' . $name;
}
}
return $engines;
}
/**
* Queue an index rebuild
*
* @return void
*/
protected function queueIndexRebuild()
{
\IPS\Content\Search\Index::i()->rebuild();
\IPS\Session::i()->log( 'acplogs__queued_search_index' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=search' ), 'search_index_rebuilding' );
}
}
@@ -0,0 +1,98 @@
<?php
/**
* @brief Manage Terms & Privacy Policy
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 07 Jun 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\settings;
/* 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;
}
/**
* terms
*/
class _terms extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'terms_manage' );
parent::execute();
}
/**
* Manage Terms & Privacy Policy
*
* @return void
*/
protected function manage()
{
$form = new \IPS\Helpers\Form;
$form->addHeader( 'terms_guidelines' );
$form->add( new \IPS\Helpers\Form\Radio( 'gl_type', \IPS\Settings::i()->gl_type, FALSE, array(
'options' => array(
'internal' => 'gl_internal',
'external' => 'gl_external',
'none' => "gl_none" ),
'toggles' => array(
'internal' => array( 'gl_guidelines_id' ),
'external' => array( 'gl_link' ),
'none' => array(),
)
) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'gl_guidelines', NULL, FALSE, array( 'app' => 'core', 'key' => 'guidelines_value', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'Guidelines', 'attachIds' => array( NULL, NULL, 'gl_guidelines' ) ) ), NULL, NULL, NULL, 'gl_guidelines_id' ) );
$form->add( new \IPS\Helpers\Form\Url( 'gl_link', \IPS\Settings::i()->gl_link, FALSE, array(), NULL, NULL, NULL, 'gl_link' ) );
$form->addHeader( 'terms_privacy');
$form->add( new \IPS\Helpers\Form\Radio( 'privacy_type', \IPS\Settings::i()->privacy_type, FALSE, array(
'options' => array(
'internal' => 'privacy_internal',
'external' => 'privacy_external',
'none' => "privacy_none" ),
'toggles' => array(
'internal' => array( 'privacy_text_id' ),
'external' => array( 'privacy_link' ),
'none' => array(),
)
) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'privacy_text', NULL, FALSE, array( 'app' => 'core', 'key' => 'privacy_text_value', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'Privacy', 'attachIds' => array( NULL, NULL, 'privacy_text' ) ) ), NULL, NULL, NULL, 'privacy_text_id' ) );
$form->add( new \IPS\Helpers\Form\Url( 'privacy_link', \IPS\Settings::i()->privacy_link, FALSE, array(), NULL, NULL, NULL, 'privacy_link' ) );
$form->addHeader( 'terms_registration' );
$form->add( new \IPS\Helpers\Form\Translatable( 'reg_rules', NULL, FALSE, array( 'app' => 'core', 'key' => 'reg_rules_value', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'RegistrationRules', 'attachIds' => array( NULL, NULL, 'reg_rules' ) ) ), NULL, NULL, NULL, 'reg_rules_id' ) );
if ( $values = $form->values() )
{
foreach ( array( 'gl_guidelines' => 'guidelines_value', 'privacy_text' => 'privacy_text_value', 'reg_rules' => 'reg_rules_value' ) as $k => $v )
{
\IPS\Lang::saveCustom( 'core', $v, $values[ $k ] );
unset( $values[ $k ] );
}
$form->saveAsSettings( $values );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__terms_edited' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_settings_terms');
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'menu__core_settings_terms', $form );
}
}